怎么看SOAP消息的Web服务方法调用? [英] How to see SOAP message as web service method calling?
问题描述
我想看看我发送到Web服务的调用净的方法。例如:
I want to see what I send to web service as calling a method in .Net. For example :
var list = service.SomeWebMethd(req);
我想看看我发送到网络serviceas SOAP消息。有什么建议立即进行删除怎么办?
I want to see what I send to web serviceas SOAP message. What shoul I do?
推荐答案
很多搜索和提问我设法专门写这个类,C#,抓住了SOAP请求和响应信封后。希望能帮助你。
After a lot of searching and asking questions I managed to write this class specifically for C# that grabs the SOAP request and response envelopes. Hope this could help you too.
首先创建一个新的类,然后复制粘贴此code为仅仅是改变了命名空间。
First create a new class and copy paste this code as is just change the namespace.
using System;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Channels;
//Set namespace to the project name
namespace yourProjectName // <-- EDIT
{
class SOAPRequestResponse : IEndpointBehavior
{
public string lastRequestXML
{
get
{
return soapInspector.lastRequestXML;
}
}
public string lastResponseXML
{
get
{
return soapInspector.lastResponseXML;
}
}
private MyMessageInspector soapInspector = new MyMessageInspector();
public void AddBindingParameters(ServiceEndpoint endPoint, BindingParameterCollection bindingParameters)
{
}
public void ApplyDispatchBehavior(ServiceEndpoint endPoint, EndpointDispatcher endPointDispatcher)
{
}
public void Validate(ServiceEndpoint endPoint)
{
}
public void ApplyClientBehavior(ServiceEndpoint endPoint, ClientRuntime clientRuntime)
{
clientRuntime.MessageInspectors.Add(soapInspector);
}
public class MyMessageInspector : IClientMessageInspector
{
public string lastRequestXML { get; private set; }
public string lastResponseXML { get; private set; }
public void AfterReceiveReply(ref Message reply, object corActionState)
{
lastResponseXML = reply.ToString();
}
public object BeforeSendRequest(ref Message request, IClientChannel channel)
{
lastRequestXML = request.ToString();
return request;
}
}
}
}
其次,你需要创建 SOA prequestRespone
类的新实例在主的形式。
Secondly you need to create a new instance of the SOAPRequestRespone
class in your main form.
SOAPRequestResponse soapENV = new SOAPRequestResponse();
您届时将有将它添加到代理类,像这样(也是主要形式):
You will then have to add it to the proxy class like so (also in main form):
service.Endpoint.Behaviors.Add(soapENV);
最后,你可以分配请求和响应信封字符串变量是这样的:
Finally you can assign the request and response envelopes to string variables like this:
string request = soapENV.lastRequestXML;
string response = soapENV.lastResponseXML;
希望这有助于你。还有其他的工具,你可以像使用SOAPUI。
Hope this helps you as well. There are other tools you can use like SOAPUI.
这篇关于怎么看SOAP消息的Web服务方法调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!