Web 服务调用期间删除了 SOAP 标头
我正在测试从 .net 客户端应用程序调用基于 SOAP 的服务,但遇到了一些奇怪的问题,SOAP 标头似乎消失了。
设置的简要说明:
我使用了 Web 服务提供商提供的 WSDL 来创建代理对象。在我的代码中声明我要调用的服务客户端的实例。构建该方法所需的有效负载,然后调用该方法。
我定义了自己的检查器,它将请求消息写入 BeforeSendRequest 函数中的文本文件,以便我可以检查正在发送的内容。
我的输出文件包含一个 SOAP 标头,指定要调用的 SOAP 操作:
<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">urn:actionName</Action>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
但是,当我在 Fiddler 中检查请求时,我看到:
POST http://itk1:4848/syncsoap HTTP/1.1
Content-Type: text/xml; charset=utf-8
VsDebuggerCausalityData: uIDPo3+FD6fhly5OnM0GeeaNhJ8AAAAAqHE+abP1+EWcEPeRvh8Oj4EFi5tL0elHlKdqfGJg1AIACQAA
SOAPAction: "urn:actionName"
Host: itk1:4848
Content-Length: 9651
Expect: 100-continue
Connection: Keep-Alive
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body
我的操作似乎已从 SOAP 信封中删除,并已成为基本标头,因此当我的服务调用获取请求,但无法在预期位置找到操作。
作为测试,我尝试使用 WebRequest.Create() 创建一个基本请求,并发布我之前从消息检查器检索到的输出文件。当它点击 Fiddler 时,会显示 SOAP 标头和操作已保留在 SOAP 信封中。
我认为这是 WCF 为我提供帮助并修改我的请求吗?我怎样才能让它停止乱搞我的消息并按照最初构建的方式发送它?
I'm testing calling a SOAP based service from a .net client app and am running in to some strange problems with the SOAP header seeming to disappear.
A brief explanation of the setup:
I've used a WSDL supplied by the webservice provider to create my proxy objects. In my code a declare an instance of the service client that I want to call. Build up the payload that the method requires and then call the method.
I've defined my own inspector which writes the request message out to a text file in the BeforeSendRequest function so I can examine what is being sent.
My output file includes a SOAP Header specifying the SOAP Action to be called:
<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">urn:actionName</Action>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
However when I examine the request in Fiddler I see:
POST http://itk1:4848/syncsoap HTTP/1.1
Content-Type: text/xml; charset=utf-8
VsDebuggerCausalityData: uIDPo3+FD6fhly5OnM0GeeaNhJ8AAAAAqHE+abP1+EWcEPeRvh8Oj4EFi5tL0elHlKdqfGJg1AIACQAA
SOAPAction: "urn:actionName"
Host: itk1:4848
Content-Length: 9651
Expect: 100-continue
Connection: Keep-Alive
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body
My action seems to have been removed from the SOAP envelope and has become a basic header so when the service I'm calling gets the request it can't find the action in the expected place.
As a test I've tried to instead create a basic request using WebRequest.Create() and post the output file that I retrieved earlier from my message inspector. When this hits Fiddler is shows that the SOAP Header and Action have been retained in in the SOAP envelope.
I presume this is WCF being helpful and amending my request for me? How can I get it to stop screwing around with my message and send it as it was originally constructed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通过使用消息检查器手动编写自己的标头解决了该问题。
即在 BeforeSendRequest 中我现在正在做:
将其与我需要的其他一些 SOAP 标头一起正确写出。
奇怪的是,如果我向调试侦听器写出请求,我会看到信封现在包含 2 个 Action 标头,但是当请求到达 Fiddler 时,信封中的单个 Action 看起来一切正常 - 我很高兴保留原始操作转换为 HTTP 标头,因为我调用的服务无论如何都需要它。
I've resolved the issue by manually writing my own headers using the message inspector.
i.e. in BeforeSendRequest I'm now doing:
Which write it out correctly along with a few other SOAP headers that I need.
Strangely, if I write out the request to my debug listeners I see that the envelope now contains 2 Action headers but by the time the request hits Fiddler everything looks ok with a single Action in the envelope - I'm happy to leave the original action converting to a HTTP Header since the service I'm calling requires that anyway.
尝试使用 IDispatchMessageFormatter 进行调试,如以下链接所示 http://blogs.msdn.com/b/carlosfigueira/archive/2011/05/03/wcf-extensibility-message-formatters.aspx
要了解 WCF 管道中的阶段,请参阅
http://msdn.microsoft.com/en-us/magazine/cc163302.aspx
Try using a IDispatchMessageFormatter for debugging as shown in this link http://blogs.msdn.com/b/carlosfigueira/archive/2011/05/03/wcf-extensibility-message-formatters.aspx
For understanding stages in WCF pipeline refer
http://msdn.microsoft.com/en-us/magazine/cc163302.aspx