无法让 ClientMessageInspector 工作 [英] Trouble Getting ClientMessageInspector to work
问题描述
这是 Stack Overflow 主题的延续 相当于数据库中的 Fiddler SOAP 请求/响应.我实现了一个 ClientMessageInspector 像这样:
This is a continuation of the Stack Overflow topic The equivalent of Fiddler SOAP Request/Response in the Database. I implemented a ClientMessageInspector like so:
public class RREMOutputMessageInspector : IClientMessageInspector
{
private string _connStringProd = String.Empty;
public void AfterReceiveReply(ref Message reply, object correlationState)
{
MessageBuffer buffer = reply.CreateBufferedCopy(Int32.MaxValue);
reply = buffer.CreateMessage();
_connStringProd = ConfigurationManager.ConnectionStrings["RREM_Gilbane_ProdConnectionString"].ToString();
NREMGilbaneTableAdapters.SOAPMessagesTableAdapter soapMessages =
new NREMGilbaneTableAdapters.SOAPMessagesTableAdapter();
soapMessages.Connection.ConnectionString = _connStringProd;
string replyString = buffer.CreateMessage().ToString();
soapMessages.Insert(replyString, DateTime.Now, "Interface12", "Interface12", "", "", "", "");
}
public object BeforeSendRequest(ref Message request, System.ServiceModel.IClientChannel channel)
{
MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue);
request = buffer.CreateMessage();
_connStringProd = ConfigurationManager.ConnectionStrings["RREM_Gilbane_ProdConnectionString"].ToString();
NREMGilbaneTableAdapters.SOAPMessagesTableAdapter soapMessages =
new NREMGilbaneTableAdapters.SOAPMessagesTableAdapter();
soapMessages.Connection.ConnectionString = _connStringProd;
string requestString = buffer.CreateMessage().ToString();
soapMessages.Insert(requestString, DateTime.Now, "Interface12", "Interface12", "", "", "", "");
return null;
}
然后我为检查员实现了一个行为:
Then I implemented a behavior for the inspector:
public class RREMBehavior : IEndpointBehavior
{
public void AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
{
throw new NotImplementedException();
}
public void ApplyClientBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
{
RREMOutputMessageInspector inspector = new RREMOutputMessageInspector();
clientRuntime.MessageInspectors.Add(inspector);
}
public void ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
{
throw new NotImplementedException();
}
public void Validate(ServiceEndpoint endpoint)
{
throw new NotImplementedException();
}
最后在我的 WCF 服务中,我在调用其他 Web 服务时有以下内容:
Finally in my WCF Service, I have the following when making a call to the other web service:
documentSvcResponse = client.retrieveDocument(authHeader, retrieveDoc);
client.Endpoint.Behaviors.Add(new RREMBehavior());
我没有在 Inspector 中遇到任何断点.您是否应该能够在检查器中设置断点.此外,该 Web 服务实现了一个循环,其中上述 2 行被多次执行.这是问题吗?我看不到任何证据表明这是有效的,请再次帮助!
I don't hit any breakpoints in my Inspector. Are you supposed to be able to set breakpoints in an inspector. Also, this web service has a loop implemented where the above 2 lines are being executed multiple times. Is that the problem? I see no evidence that this is working, Help again please!
推荐答案
是的,你应该这样做.您是否已将端点行为和扩展添加到您的 web.config 文件中?看看这篇 msdn 文章:http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iclientmessageinspector(v=vs.110).aspx
Yes you should. Have you added the endpointbehavior and extensions to your web.config file? Have a look at this msdn article: http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iclientmessageinspector(v=vs.110).aspx
我不太明白你关于循环的问题?不过听起来有点奇怪.
I don't really understand your question regarding the loop? But it sound a bit strange.
这篇关于无法让 ClientMessageInspector 工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!