13

这是我的问题。我正在访问一个 Web 服务(托管在基于 Java 的服务器上),它只接受文本编码的请求,但它返回 MTOM 响应。我发现如果我将 Web 服务设置为 RequireMtom,它会发送一个 Mtom 请求!不幸的是,服务器在 Mtom 请求上阻塞并返回 500 错误。但是,如果我将其设置为文本消息编码,则响应会正确返回,并带有一个多部分 MIME (MTOM) 响应,该响应会导致 Microsoft Web 服务 API 出错(下面的示例错误)。它期待一个文本编码的响应,因为请求是文本编码的。我只想在响应中使用 RequireMtom。有人能帮我一下吗?

正如您在下面的错误中所见(发生在标准 Web 服务 API、WCF 或 WSE3 中),当我使用文本编码发送请求时,响应正确返回,其中包含多部分/相关响应中的所有数据,但是.net 框架窒息!

WSE 的错误消息:

Client found response content type of 'multipart/related; type="text/xml"; start="<1AE0B46A85B0186B5D136D12E1EE286E>";  boundary="----=_Part_209564_1891070135.1226526701833"', but expected 'text/xml'.
The request failed with the error message:

 at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   at TestWseService.AdesaJasperWse.ManagementServiceService.runReport(String requestXmlString) in C:\Documents and Settings\xxx\My Documents\Visual Studio 2005\Projects\TestWseService\Web References\AdesaJasperWse\Reference.cs:line 229
   at TestWseService.Form1.buttonRunService_Click(Object sender, EventArgs e) in C:\Documents and Settings\xxx\My Documents\Visual Studio 2005\Projects\TestWseService\Form1.cs:line 42

WCF 的错误消息

The content type multipart/related; type="text/xml"; start="<30ED8FE3004CDA67723CC7164A6CFEEC>";    boundary="----=_Part_209545_389093169.1226526546805" of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: 

Server stack trace: 
   at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException)
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

请求(带有文本消息编码):

POST /jasperserver-pro/services/repository HTTP/1.1
Content-Type: text/xml; charset=utf-8
VsDebuggerCausalityData: uIDPo7V2+runH+xGudbec7ueUU8AAAAA7H9vL3stlkCBofMgLa5DWkQOHHpBdy1Ek6P6nXx7FpsACQAA
SOAPAction: ""
Authorization: Basic amFzcGVyYWRtaW46akBzcDNyQGRtJW4=
Host: reports.dev.xxx.com
Content-Length: 789
Expect: 100-continue

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><q1:runReport xmlns:q1="http://axis2.ws.jasperserver.jaspersoft.com"><requestXmlString xsi:type="xsd:string">&lt;request operationName="runReport" locale="en"&gt;&#xD;
&lt;argument name="RUN_OUTPUT_FORMAT"&gt;HTML&lt;/argument&gt;&#xD;
&lt;resourceDescriptor name="" wsType="" uriString="/BusinessIntelligence/MOS/Reports/dotnettest" isNew="false"&gt;&#xD;
&lt;label&gt;null&lt;/label&gt;&#xD;
&lt;parameter name="testparam"&gt;1&lt;/parameter&gt;&#xD;
&lt;/resourceDescriptor&gt;&#xD;
&lt;/request&gt;</requestXmlString></q1:runReport></s:Body></s:Envelope>

响应(带有文本消息编码):

HTTP/1.1 200 OK
Date: Wed, 12 Nov 2008 21:49:04 GMT
Server: IBM_HTTP_Server
Surrogate-Control: no-store
Set-Cookie: JSESSIONID=0000z5pH1xEMyulueASctjru2qe:13kftunf6; Path=/
Expires: Thu, 01 Dec 1994 16:00:00 GMT
Cache-Control: no-cache="set-cookie, set-cookie2"
Content-Length: 2580
Content-Type: multipart/related; type="text/xml"; start="<30ED8FE3004CDA67723CC7164A6CFEEC>";   boundary="----=_Part_209545_389093169.1226526546805"
Content-Language: en-US


------=_Part_209545_389093169.1226526546805
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: binary
Content-Id: <30ED8FE3004CDA67723CC7164A6CFEEC>

<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><ns1:runReportResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://axis2.ws.jasperserver.jaspersoft.com"><runReportReturn xsi:type="xsd:string">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;operationResult version=&quot;2.0.1&quot;&gt;
    &lt;returnCode&gt;&lt;![CDATA[0]]&gt;&lt;/returnCode&gt;
&lt;/operationResult&gt;
</runReportReturn></ns1:runReportResponse></soapenv:Body></soapenv:Envelope>
------=_Part_209545_389093169.1226526546805
Content-Type: text/html
Content-Transfer-Encoding: binary
Content-Id: <report>

<html>
<head>
  <title></title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  <style type="text/css">
    a {text-decoration: none}
  </style>
</head>
<body text="#000000" link="#000000" alink="#000000" vlink="#000000">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr><td width="50%">&nbsp;</td><td align="center">

<a name="JR_PAGE_ANCHOR_0_1"/>
<table style="width: 595px" cellpadding="0" cellspacing="0" border="0" bgcolor="white">
<tr>
  <td><img alt="" src="images/px" style="width: 35px; height: 1px;"/></td>
  <td><img alt="" src="images/px" style="width: 189px; height: 1px;"/></td>
  <td><img alt="" src="images/px" style="width: 253px; height: 1px;"/></td>
  <td><img alt="" src="images/px" style="width: 118px; height: 1px;"/></td>
</tr>
<tr valign="top">
  <td colspan="4"><img alt="" src="images/px" style="width: 595px; height: 20px;"/></td>
</tr>
<tr valign="top">
  <td><img alt="" src="images/px" style="width: 35px; height: 30px;"/></td>
  <td valign="middle"><span style="font-family: Arial; font-size: 12.0px; font-weight: bold;">The value of the parameter is:</span></td>
  <td valign="middle"><span style="font-family: Arial; background-color: #FFFFFF; font-size: 12.0px; font-weight: bold;">1</span></td>
  <td><img alt="" src="images/px" style="width: 118px; height: 30px;"/></td>
</tr>
<tr valign="top">
  <td colspan="4"><img alt="" src="images/px" style="width: 595px; height: 20px;"/></td>
</tr>
</table>

</td><td width="50%">&nbsp;</td></tr>
</table>
</body>
</html>

------=_Part_209545_389093169.1226526546805--

请求(使用 Mtom 消息编码):

POST /jasperserver-pro/services/repository HTTP/1.1
MIME-Version: 1.0
Content-Type: multipart/related; type="application/xop+xml";start="<http://tempuri.org/0>";boundary="uuid:fafcdca7-94f7-4884-a8d4-5c6d50dbe8ef+id=1";start-info="text/xml"
VsDebuggerCausalityData: uIDPo+cN2kKX2odFuUVaER0j60gAAAAAmfYaGH7Ow0WQOcwhebh5pqmDl29omcVOtwVGa10IWewACQAA
SOAPAction: ""
Authorization: Basic amFzcGVyYWRtaW46akBzcDNyQGRtJW4=
Host: reports.dev.xxx.com
Content-Length: 1031
Expect: 100-continue


--uuid:fafcdca7-94f7-4884-a8d4-5c6d50dbe8ef+id=1
Content-ID: <http://tempuri.org/0>
Content-Transfer-Encoding: 8bit
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><q1:runReport xmlns:q1="http://axis2.ws.jasperserver.jaspersoft.com"><requestXmlString xsi:type="xsd:string">&lt;request operationName="runReport" locale="en"&gt;&#xD;
&lt;argument name="RUN_OUTPUT_FORMAT"&gt;HTML&lt;/argument&gt;&#xD;
&lt;resourceDescriptor name="" wsType="" uriString="/BusinessIntelligence/MOS/Reports/dotnettest" isNew="false"&gt;&#xD;
&lt;label&gt;null&lt;/label&gt;&#xD;
&lt;parameter name="testparam"&gt;1&lt;/parameter&gt;&#xD;
&lt;/resourceDescriptor&gt;&#xD;
&lt;/request&gt;</requestXmlString></q1:runReport></s:Body></s:Envelope>
--uuid:fafcdca7-94f7-4884-a8d4-5c6d50dbe8ef+id=1--

响应(使用 Mtom 消息编码):

HTTP/1.1 500 Internal Server Error
Date: Wed, 12 Nov 2008 21:47:42 GMT
Server: IBM_HTTP_Server
Surrogate-Control: no-store
$WSEP: 
Set-Cookie: JSESSIONID=0000_iMrdp-TnK9FG3jZFzjx_hA:13kftunf6; Path=/
Expires: Thu, 01 Dec 1994 16:00:00 GMT
Cache-Control: no-cache="set-cookie, set-cookie2"
Content-Length: 12
Connection: close
Content-Type: text/html;charset=UTF-8
Content-Language: en-US

Error 500: 

这是一个支持微软不支持混合编码理论的链接:

WSE 3.0:MTOM 请求必须响应 MTOM?

超高!

4

5 回答 5

8

是的,您可以使用 WCF 发送短信并获得 mtom 回复(反之亦然)。

看...

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/480f1bc4-1fc4-40e9-a2ed-efcf3009d6ef

于 2009-11-25T19:32:52.427 回答
2

我对此进行了一些研究,坏消息是从 WCF 的角度来看,请求和响应必须使用相同的编码。所以,是的,上面的答案是非常正确的。您必须与服务提供商组织以在请求和响应中启用 MTOM。据我所知,除了更改 SOAP mime-type 之外,MTOM 请求不会对他的应用程序产生任何影响。

于 2008-11-20T09:04:54.620 回答
1

这是我在另一个论坛上得到的回复。它基本上说问题出在Java端的Axis2上。不幸的是,在这种情况下,这不在我的控制之下。

cherry111 - 发表于 2008 年 11 月 15 日星期六 12:52:08

您需要更改 AXIS2 Web 服务的配置。您可能知道可以在两个地方启用 MTOM。一个在 service.xml 中,另一个在 axis.xml 中。Java推荐你在service.xml中设置,但是.net wse3.0客户端不喜欢。如果您在axis.xml 中启用MTOM,它应该可以工作。

于 2008-11-18T05:01:39.837 回答
1

是的,WCF 有这个强制性要求,没有,因为你可以像我一样解决它。

我写了一个 MultiContentTypeMessageEncoder,它封装了 3 个不同的编码器文本,mtom 和 fi。如果可能的话,我还计划封装一个 gpb 编码器,如果将来有充分的理由这样做

于 2010-03-09T10:37:49.637 回答
0

[WSE 3.0] 您可以使用单个覆盖方法 GetWebResponse 定义从 WSE3 代理对象继承的新类。

在 GetWebResponse 方法中,您可以根据响应的内容类型简单地选择是否要使用 mtom 编码。

之后,您必须使用此代理类而不是生成的代理类。

PS:必须使用 wsewsdl3 作为 WebClient 生成 WSE3 代理类(将此选项 /type:webClient 添加到命令行)。

参考: http: //www.codeproject.com/Tips/46257/Solution-to-WSE-error-for-WSE-clients-needing

于 2015-10-06T08:41:01.680 回答