【问题标题】:Get Soap envelope content in WCF Service在 WCF 服务中获取肥皂信封内容
【发布时间】:2018-10-16 11:46:44
【问题描述】:

当我的(我的)Wcf 服务出现异常时,如何获取 Soap 信封的内容?

实际上,我有一个简单的 Web 服务,当服务捕获异常时,我想通过该服务向我发送一封带有肥皂信封的电子邮件。

-- 我有什么--

我创建了一个简单的 Web 服务:只有两个文件 + Web.Config

IHelloService.cs 文件:

[ServiceContract(Namespace="http://www.example.com/")]
public interface IHelloService
{
  [OperationContract]
  string SayHelloTo(string name);
}

还有,HelloService.svc 文件:

public class HelloService : IHelloService
{
   public HelloService() { }
   public string SayHelloTo(string name)
   {
        // Imagine I want to do something with all names with only 3 characters
        if(!string.IsNullOrEmpty(name))
        {
            if (name.Length == 3)
            {
                // Here, I want to have the soap envelope content passed to Ws
                // to do something with it, send it to someone, log it to file ...
            }
        }
     return "Hello " + name;         
   }
}

配置文件:

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5.2"/>
    <httpRuntime targetFramework="4.5.2"/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

-- 结束--

【问题讨论】:

  • 需要比这更多的信息.​​..
  • 不清楚。愿您花几分钟时间阅读How to Ask 和minimal reproducible example。既然您对我们的指南有更多了解,请花点时间edit 您的问题,了解更多信息。你说的这个例外是什么?它的原因是什么意思?发送到 WebService 的格式是否错误?是信息处理过程中的错误吗?这是预期的错误吗?
  • 但我猜你必须在 try catch 中扭曲一些东西。构建您的邮件并决定您发送回给用户的内容。
  • 我刚刚发布了我拥有的小型 Web 服务 :)

标签: c# web-services wcf soap


【解决方案1】:

您可以在 WCF 服务上启用跟踪。这将有助于诊断进出服务的内容问题。 Configuring Tracing

【讨论】:

    猜你喜欢
    • 2015-08-25
    • 1970-01-01
    • 1970-01-01
    • 2014-06-02
    • 2018-04-12
    • 2021-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多