MTOM错误访问基于CXF的Web服务 [英] MTOM error accessing CXF based web service

查看:67
本文介绍了MTOM错误访问基于CXF的Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试访问由第三方(我在服务器上没有控制权)使用CXF创建的Web服务,该服务正在使用Mtom答复我的请求.我正在将WCF与.net 4/VS2010一起使用(也在.net 4.5/VS2013中进行了尝试,结果相同)

I'm trying to access a web service created with CXF by a third party (I've no control on the server) which is answering my request using Mtom. I'm using WCF with .net 4/VS2010 (tried also in .net 4.5/VS2013, with identical results)

我已经通过Visual Studio中的添加服务引用导入了WDSL定义,而没有出现问题.问题是,一旦我尝试使用生成的类访问Web服务,出现错误消息创建错误"的异常 MTOM消息的阅读器"和InnerException.Message具有Content-ID'< root.message@cxf.apache.org>的MIME部分"找不到."

I've imported the WDSL definition via add service reference in Visual Studio without problems. The problem is that as soon as I try to access the web service with the generated classes,  an exception is raised with an error message "Error creating a reader for the MTOM message", and an InnerException.Message "MIME part with Content-ID '<root.message@cxf.apache.org>' not found."

(原始)Web服务器响应(发送一个简单的应用程序登录请求)就是这样,它使用我收集的mtom/xop进行编码.

The (raw) web server response (a simple application login request being sent) is as such, it is encoded with mtom/xop I gather.

HTTP/1.1 200 OK
Date: Sat, 07 Dec 2013 08:21:34 GMT
Server: Apache-Coyote/1.1
Content-Type: multipart/related; type="application/xop+xml"; boundary="uuid:233e2f8b-7e9c-4c9d-8639-d95a51bf4cbb"; start="<root.message@cxf.apache.org>"; start-info="text/xml"
Content-Length: 539
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive


--uuid:233e2f8b-7e9c-4c9d-8639-d95a51bf4cbb
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml";
Content-Transfer-Encoding: binary
Content-ID: <root.message@cxf.apache.org>

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:loginResponse xmlns:ns2="http://v1.api.web.xxxxxxxxx.yyy.zz/"><return><error>NONE</error><value>NDIjImVBOihyTyY9b3MgVyNeajxBaW9VMj8wWEFcLjFJ</value></return></ns2:loginResponse></soap:Body></soap:Envelope>
--uuid:233e2f8b-7e9c-4c9d-8639-d95a51bf4cbb--

从一个简单的Windows窗体测试应用程序中摘录的调用c#代码是这个

the calling c# code snipped from a simple windows forms test application is this

//I create the binding in code for clarity
 BasicHttpBinding binding = new BasicHttpBinding();
            binding.MessageEncoding = WSMessageEncoding.Mtom;
            binding.TransferMode = TransferMode.Buffered;
            binding.TextEncoding = Encoding.UTF8;
            
                EndpointAddress epa = new EndpointAddress("http://aaaaaaaaaa.xxxxxx.yy/ws/v1");

//GN is the automatically generated namespace using add service reference
            GN.WebApiWebServiceClient wawsc = new GN.WebApiWebServiceClient(binding, epa);

//first request to web service
            GN.stringResponse sr = new GN.stringResponse();
            

            try
            {
                sr = wawsc.login("apiusername", "secretpassword");
            }
//an exception is invariably raised here
            catch (Exception ex)
            {
                textBox1.Text = ex.Message + " " + ex.InnerException.Message";
            }

正如我所说,异常消息是为MTOM消息创建读取器时出错",而InnerException.Message则是具有Content-ID'< root.message@cxf.apache.org>的MIME部分".找不到."

As I said, the exception message is "Error creating a reader for the MTOM message", and an InnerException.Message "MIME part with Content-ID '<root.message@cxf.apache.org>' not found."

在服务器上使用.Text编码不起作用,当然,使用.net 2.0样式的Web服务似乎不支持mtom.在绑定上还有其他我可能会忽略的设置吗?

Using .Text encoding on the server doesn't work, of course, using .net 2.0 style web services doesn't seem to support mtom. Is there some other setting on the binding that I may have overlooked?

推荐答案

请尝试通过@ 玛格丽特 碱液-MSFT  中:
http://social.msdn.microsoft.com/Forums/vstudio/zh-CN/4cfb334b-554c-464c-9efc-6031b9fc1e93/malformed-mtom-message-at-service

Please try to check the following reply post by @Margaret  Lye - MSFT in:
http://social.msdn.microsoft.com/Forums/vstudio/en-US/4cfb334b-554c-464c-9efc-6031b9fc1e93/malformed-mtom-message-at-service .

我们发现仅转发http和mtom消息存在一个集成问题.事实证明,如果转发包含HttpRequestMessageProperty或HttpResponseMessageProperty的消息,则HTTP标头将被 消息属性中的设置.这些设置代表您的转发服务刚收到的消息中的内容.此特定问题是由您的内容类型标头被覆盖引起的,这意味着边界字节不正确.

We've discovered there is an integration issue with just forwarding a http and mtom message. It turns out that if you forward a message containing a HttpRequestMessageProperty or a HttpResponseMessageProperty, your http headers will be clobbered by the settings in the message property. These settings represent what was on the message your forwarding service just received. This particular issue is caused by your content-type header being overwritten which means the boundary bytes are incorrect.

您可能应该完全删除属性.

对于传入的请求消息:

message.Properties.Remove(HttpRequestMessageProperty.Name);

对于收到的回复消息:

message.Properties.Remove(HttpResponseMessageProperty.Name);

最好的问候,
艾米·彭

Best Regards,
Amy Peng


这篇关于MTOM错误访问基于CXF的Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆