0
這是堆棧溢出主題The equivalent of Fiddler SOAP Request/Response in the Database的延續。我實現了一個ClientMessageInspector像這樣:無法使ClientMessageInspector工作
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;
}
然後我實現了檢查行爲:
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服務時以下幾點:
documentSvcResponse = client.retrieveDocument(authHeader, retrieveDoc);
client.Endpoint.Behaviors.Add(new RREMBehavior());
我在檢查員中沒有遇到任何斷點。你應該能夠在檢查員中設置斷點。此外,這個Web服務有一個循環,在上面的兩行被執行多次。這是問題嗎?我看不到有證據表明這是行得通的,請再說一次!
對不起。我無法從該頁面的示例中找出正面或反面。它也似乎是不正確的,因爲郵件的副本沒有存儲,所以它沒有消失? – user2471435