gpt4 book ai didi

c# - WCF 客户端如何使用多部分/相关的 Java Web 服务响应?

转载 作者:搜寻专家 更新时间:2023-11-01 02:46:56 26 4
gpt4 key购买 nike

我编写了一个使用 Java 网络服务的 WCF C# 客户端:

var client = new abcClient("abc");
var response = client.AbcTransaction(msg);

来自 web.config 的 WCF 绑定(bind)信息是:

<customBinding>
<binding name="abcSOAP">
<textMessageEncoding messageVersion="Soap12" />
<httpsTransport requireClientCertificate="true" />
</binding>
</customBinding>

它看起来很简单,对吧? ...事实上,SoapFaults 很容易使用:

HTTP/1.1 500 Internal Server Error
Content-Length: 783
Content-Type: application/soap+xml;charset=UTF-8
Server: Microsoft-IIS/8.0
Date: Mon, 18 Nov 2013 14:06:18 GMT

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Body><soap:Fault>...

但是,网络服务以多部分/相关内容类型发送“常规”响应:

HTTP/1.1 200 OK
Content-Type: multipart/related; type="application/xop+xml"; boundary="uuid:c79210c3-bbef-4aa3-82ae-6a20c7a96564"; start="<root.message@cxf.apache.org>"; start-info="application/soap+xml"
Content-Encoding: gzip
Vary: Accept-Encoding
Server: Microsoft-IIS/8.0
Date: Mon, 18 Nov 2013 14:11:25 GMT
Content-Length: 658

--uuid:c79210c3-bbef-4aa3-82ae-6a20c7a96564
Content-Type: application/xop+xml; charset=UTF-8; type="application/soap+xml";
Content-Transfer-Encoding: binary
Content-ID: <root.message@cxf.apache.org>

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">...

这会导致 WCF 客户端出现 ProtocolException,因为 WCF 客户端不期望多部分/相关的答案。 ProtocolException 消息是(德语):

Der Inhaltstyp "multipart/related; type="application/xop+xml"; boundary="uuid:ead716a3-4b8b-4207-ad66-b9f18ae368b2"; start=""; start-info="application/soap+xml"" der Antwortnachricht stimmt nicht mit dem Inhaltstyp der Bindung (application/soap+xml; charset=utf-8) überein. Wenn Sie einen benutzerdefinierten Encoder verwenden, sollten Sie sicherstellen, dass die IsContentTypeSupported-Methode korrekt implementiert ist. Die ersten 1024 Bytes der Antwort waren: ...

英语:

The content type "multipart/related; type="application/xop+xml"; boundary="uuid:ead716a3-4b8b-4207-ad66-b9f18ae368b2"; start=""; start-info="application/soap+xml"" of the response message does not match the content type of the binding (application/soap+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: ...

有谁知道如何使用 WCF 客户端(不使用 HttpWebRequest 类)使用此多部分/相关消息?这个场景有可用的配置吗?

最佳答案

Max' 和 Mehmet 的提示显示了正确的方向,但我不得不做更多的改变。由于我使用了 中的元素,wcf 配置忽略了 messageEncoding="Mtom"属性。

与其使用属性,不如直接使用元素更好:

<binding name="energylinkSOAP">
<mtomMessageEncoding messageVersion="Soap12" />
<httpsTransport requireClientCertificate="true" />
</binding>

通过它你还可以定义更多的配置,比如messageVersion。

关于c# - WCF 客户端如何使用多部分/相关的 Java Web 服务响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20049981/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com