如何在使用 WCF(或 WSE 3)的 Web 服務客戶端應用程序的請求和響應中混合消息編碼類型(文本/MTOM)? (How do I mix message encoding types (Text/MTOM) in the Request & Response of a Web Service client application using WCF (or WSE 3)?)


問題描述

如何在使用 WCF(或 WSE 3)的 Web 服務客戶端應用程序的請求和響應中混合消息編碼類型(文本/MTOM)? (How do I mix message encoding types (Text/MTOM) in the Request & Response of a Web Service client application using WCF (or WSE 3)?)

這是我的問題。我正在訪問一個 Web 服務(託管在基於 Java 的服務器上),它只接受文本編碼的請求,但它返回 MTOM 響應。我發現如果我將 Web 服務設置為 RequireMtom,它會發送一個 Mtom 請求!不幸的是,服務器在 Mtom 請求上阻塞並返回 500 錯誤。但是,如果我將其設置為文本消息編碼,則響應會正確返回,並帶有一個多部分 MIME (MTOM) 響應,該響應會導致 Microsoft Web 服務 API 出錯(下面的示例錯誤)。它期待一個文本編碼的響應,因為請求是文本編碼的。我只想在響應中使用 RequireMtom。任何人都可以在這裡幫助我嗎?

正如您在下面的錯誤中看到的(發生在標準 Web 服務 API、WCF 或 WSE3 中),當我使用文本編碼發送請求時,


參考解法

方法 1:

Yes you can send a text message and get an mtom reply(or vise versa)with WCF.

see...

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

方法 2:

I researched a bit about this and the bad news is that from WCF point of view the request and response MUST use the same enconding. So yeah, the answer above is quite correct. You have to organize with service provider to enable MTOM on both request and response. The MTOM request will not have any impact on his application, apart from changing the SOAP mime‑type, as far as I know.

方法 3:

Here is a reply I got on another forum. it basically says that the problem is with Axis2 on the Java side. Unfortunately, that is not under my control in this case.

cherry111 ‑ Posted on Saturday, November 15, 2008 12:52:08 AM

You need change the configuration on your AXIS2 web service. You may know you can enable MTOM at two places. One is in service.xml and the other is in the axis.xml. Java recommends you set it in service.xml, but .net wse3.0 client does not like it. If you enable MTOM in axis.xml, it should work.

方法 4:

Yes WCF has that mandated requirement and NO, because you can work around it like i did.

I wrote a MultiContentTypeMessageEncoder that encapsulates 3 different encoders text, mtom and fi. I also plan to encapsulate a gpb encoder if possible and if there is a good reason to do so, in the future

方法 5:

[WSE 3.0] You can define a new class that inherits from your WSE3 proxy object with a single override method GetWebResponse.

In GetWebResponse method, you can simply choose if you want to use the mtom encoding according to the response's content‑type.

After that, you have to use this proxy class instead of the generated one.

PS: The WSE3 proxy class have to be generated using wsewsdl3 as a WebClient (add this option /type:webClient to the commend line).

Reference: http://www.codeproject.com/Tips/46257/Solution‑to‑WSE‑error‑for‑WSE‑clients‑needing.

(by komma8.komma1Eric SchlosserWagner Silveirakomma8.komma1Siddharth SaweZayani Chiheb)

參考文件

  1. How do I mix message encoding types (Text/MTOM) in the Request & Response of a Web Service client application using WCF (or WSE 3)? (CC BY‑SA 2.5/3.0/4.0)

#wse #mtom #web-services #.net #wcf






相關問題

Windows 2000 下的 WSE 服務器 (WSE Server under Windows 2000)

在 wse 中使用自己的異常,而不僅僅是 SoapException (Using own exceptions in wse, not only SoapException)

從Java調用.NET Web服務(WSE 2/3,WS-Security) (Calling .NET Web Service (WSE 2/3, WS-Security) from Java)

從 WCF 調用 WSE 服務的提示? (Tips for calling WSE service from WCF?)

在 Web 服務 (WSE) 中公開自定義類型(類) (exposing custom types (classes) in a web service (WSE))

在具有自定義類型的 WSE 服務中,構造函數是否在消費客戶端工作? (In WSE services, with custom types, do constructors work on the consuming client's side?)

從 Visual Studio 2005 遷移到 2008 時要注意什麼? (What to look out for when moving from Visual Studio 2005 to 2008?)

通過代理調用 WSE Web 服務 (Calling a WSE web-service though a proxy)

VS 2008 上的 WSE 2.0 SP2 (WSE 2.0 SP2 on VS 2008)

如何在使用 WCF(或 WSE 3)的 Web 服務客戶端應用程序的請求和響應中混合消息編碼類型(文本/MTOM)? (How do I mix message encoding types (Text/MTOM) in the Request & Response of a Web Service client application using WCF (or WSE 3)?)

從 wsdl 創建肥皂 Web 服務客戶端,沒有合同方法 (Create soap web service client from wsdl with no contract methods)

Windows 上的 X.509 證書入門 (Primer for X.509 certificates on Windows)







留言討論