当前位置:  开发笔记 > 编程语言 > 正文

如何使用WCF(或WSE 3)在Web服务客户端应用程序的请求和响应中混合消息编码类型(Text/MTOM)?

如何解决《如何使用WCF(或WSE3)在Web服务客户端应用程序的请求和响应中混合消息编码类型(Text/MTOM)?》经验,为你挑选了1个好方法。

这是我的问题.我正在访问一个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

<request operationName="runReport" locale="en">
<argument name="RUN_OUTPUT_FORMAT">HTML</argument>
<resourceDescriptor name="" wsType="" uriString="/BusinessIntelligence/MOS/Reports/dotnettest" isNew="false">
<label>null</label>
<parameter name="testparam">1</parameter>
</resourceDescriptor>
</request>

响应(使用文本消息编码):

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"?>
<operationResult version="2.0.1">
    <returnCode><![CDATA[0]]></returnCode>
</operationResult>

------=_Part_209545_389093169.1226526546805
Content-Type: text/html
Content-Transfer-Encoding: binary
Content-Id: 



  
  
  


 
The value of the parameter is: 1
 
------=_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="";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: 
Content-Transfer-Encoding: 8bit
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"

<request operationName="runReport" locale="en">
<argument name="RUN_OUTPUT_FORMAT">HTML</argument>
<resourceDescriptor name="" wsType="" uriString="/BusinessIntelligence/MOS/Reports/dotnettest" isNew="false">
<label>null</label>
<parameter name="testparam">1</parameter>
</resourceDescriptor>
</request>
--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: 

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

WSE 3.0:MTOM请求的MTOM响应是强制性的吗?

UHG!



1> 小智..:

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

看到...

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

推荐阅读
放ch养奶牛
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有