像那样的MyMessageInspector
public class MyMessageInspector : IClientMessageInspector
{
public string LastRequestXML { get; private set; }
public string LastResponseXML { get; private set; }
public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
{
LastResponseXML = reply.ToString();
}
public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
{
LastRequestXML = request.ToString();
return request;
}
}
我有ClientCredentials
ClientCredentials =
{
UserName =
{
UserName = "usr",
Password = "pass"
}
}
在请求标题之前,我添加了此检查器。 soapClient是我的Web服务客户端对象
soapClient.Endpoint.Behaviors.Add(InspectorBehavior);
我正在创建我的肥皂请求标题,如下所示
requestHeader.cC = "Something";
requestHeader.cU = "Something";
requestHeader.channel = WebService.ChannelType.WEB;
requestHeader.aC = "Something";
requestHeader.ap = "Something";
requestHeader.ag = "Something";
requestHeader.cTI = "Something";
requestHeader.languageCode = LanguageCodeType.TR;
我添加了网络服务:参考资料 - >添加服务参考
这是InspectorBehavior LastRequestXML返回
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://..blablaRequest</Action>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<WebService xmlns="http://..ws/">
<requestHeader xmlns="">
<cCxmlns="http://..requestHeader">Something</cC>
<cU xmlns="http://..requestHeader">Something</cU>
<aC xmlns="http://..requestHeader">Something</aC>
<ap xmlns="http://..requestHeader">Something</ap>
<ag xmlns="http://..requestHeader">Something</ag>
<cTI xmlns="http://..requestHeader">Something</cTI>
</requestHeader>
...
</WebService>
</s:Body>
</s:Envelope>
那么为什么enum类型的channel和languageCode没有显示在检查器上?我在调用我的网络服务时收到此错误代码:
System.ServiceModel.CommunicationException: 'Server returned an invalid SOAP Fault. Please see InnerException for more details.'
我因为枚举类型而思考?