(我的)Wcf服务中出现异常时,如何获得肥皂信封的内容?
实际上,我有一个简单的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>
-结束-