为什么在使用Custom MessageEncoder时缺少Soap标头 [英] Why are the soap headers missing when using Custom MessageEncoder
问题描述
我正在创建与WCF示例项目(WF_WCF_Samples\WCF\Extensibility\\MessageEncoder\Compression)类似的自定义消息编码器。
I am creating a custom message encoder similar to what you have in the WCF example projects(WF_WCF_Samples\WCF\Extensibility\MessageEncoder\Compression).
我遇到的问题是在发送请求时,使用默认的textMessageEncoder进行压缩后会生成此请求。
The problem I am having is when sending a request, using the default textMessageEncoder with no compression produces this request after encoding.
但是,当我将自定义编码器用于gzip压缩并从soapUI发送请求时,是我得到的。
However, when I am using my custom encoder with gzip compression and sending a request from soapUI this is what I get.
您可以查看缺少的收件人和操作。最终给了我这个例外。
As you can see the To and Action are missing. It ends up giving me this exception.
The SOAP action specified on the message, '', does not match the HTTP SOAP Action,
可以通过在MessageEncoder中手动添加以下内容来补救此问题
This can be remedied by adding the following manually in the MessageEncoder
message.Headers.To = new Uri("http://localhost:19860/Service1.svc");
message.Headers.Action = @"http://tempuri.org/IService1/GetData";
所以我的问题是为什么会这样?为什么在使用自定义MessageEncoder时,即使我只是使用内部编码器来创建消息,我为什么也缺少标题?
So my question is why is this happening? Why am I missing my headers when using the custom MessageEncoder even though I am just using the inner encoder to create the message?
这里是完整的解决方案。要对其进行测试,您只需要soap ui并将请求发送到 http:// localhost:19860 / Service1.svc
Here is the full solution. To test it you just need soap ui and send request to http://localhost:19860/Service1.svc
https://github.com/janmchan/ WCFCompression
推荐答案
最后找到了问题。这似乎是WCF上的错误。 Soap1.2中实际上并不需要SoapHeaders中的Action和To,但是出于某种原因,即使使用该版本,即使仅使用内部编码器的MessageEncoder,即使我只是调用内部编码器的ReadMessage,我仍然会遇到WCF问题。解决方案也很困惑。如错误消息所示,该Action与soap操作不匹配,因此我只需要添加一个标头SOAPAction,即使它为空。
Finally found the issue. This seems to be a bug on WCF. The Action and To in SoapHeaders should not really be required on Soap 1.2 but for some reason even when using that version, I still get this issue with WCF only when using a custom MessageEncoder even if I'm just calling the inner encoder's ReadMessage. The solution is quite perplexing as well. As the error message suggest, the Action does not match the soap action so I just needed to add a header SOAPAction even if it is blank.
以下是该帖子的帮助内容我找到了解决方案。
Here is the post that helped me find the solution.
这篇关于为什么在使用Custom MessageEncoder时缺少Soap标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!