我查看了我在本网站上可以找到的所有相关帖子,并且我已经浏览了互联网...而且我很难知道如何在将WCF的响应发送回之前阅读WCF的SOAP响应。客户端。
我希望以最终形式阅读响应(包含XML中的soap信封元素)并将其发送到我的自定义日志过程。
请注意,我必须使用自定义日志功能,该功能将响应作为字符串接受并将其发送到SQL数据库(未显示)。这必须在运行时由代码处理每个响应;我不能简单地使用一些第三方记录/跟踪工具。
这是我的WCF服务代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using MSADataAccess;
using System.Web.Configuration;
using System.ServiceModel.Channels;
namespace svcIDIVS
{
public class VINS : IVINS
{
public string VerifyInsurance(string coverageRequest)
{
string responseMessage = null;
DataAccess da = new DataAccess();
responseMessage = da.VerifyInsurance(coverageRequest);
return responseMessage;
}
}
}
我需要将responseMessage及其SOAP Envelope读入字符串。看起来应该是这样的:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header />
<s:Body>
<VerifyInsuranceResponse xmlns="http://tempuri.org/">
<VerifyInsuranceResult><CoverageResponseDocument PublicationVersion="00200809" PublicationDate="2008-11-05" xmlns="http://www.iicmva.com/CoverageVerification/">
<Detail>
<PolicyInformation>
<CoverageStatus>
<ResponseDetails>
<ResponseCode>Unconfirmed</ResponseCode>
<UnconfirmedReasonCode>VIN2</UnconfirmedReasonCode>
</ResponseDetails>
</CoverageStatus>
<OrganizationDetails>
<NAIC>14788</NAIC>
<!-- this can be echoed from the request or provide the actual NAIC that has evidence of coverage -->
</OrganizationDetails>
<PolicyDetails>
<!-- this section can be echoed from the request -->
<VerificationDate>07/16/2008 00:00:00</VerificationDate>
<PolicyKey>03K85845</PolicyKey>
<PolicyState>CT</PolicyState>
</PolicyDetails>
</PolicyInformation>
</Detail>
</CoverageResponseDocument>
</VerifyInsuranceResult>
</VerifyInsuranceResponse>
</s:Body>
答案 0 :(得分:1)
WCF有Message Dispatcher Inspector,您可以在发送/回复服务之前拦截邮件并进行验证。
public class BodMessageInspector : IDispatchMessageInspector
{
public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
{
return instanceContext;
}
public void BeforeSendReply(ref Message reply, object correlationState)
{
// DO your stuff here and validate your reply Message
}
}