【发布时间】:2023-12-18 04:58:01
【问题描述】:
我编写了一个使用 Java Web 服务的 WCF C# 客户端:
var client = new abcClient("abc");
var response = client.AbcTransaction(msg);
来自 web.config 的 WCF 绑定信息是:
<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>...
但是,网络服务以 multipart/related content-type 发送“常规”响应:
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"; 边界="uuid:ead716a3-4b8b-4207-ad66-b9f18ae368b2"; 开始=“”; 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 实施主义者。 Die ersten 1024 Bytes der Antwort 商品:...
英文:
内容类型“multipart/related; type="application/xop+xml"; 边界="uuid:ead716a3-4b8b-4207-ad66-b9f18ae368b2"; 开始=“”; 响应消息的 start-info="application/soap+xml"" 与绑定的内容类型不匹配 (application/soap+xml; charset=utf-8)。如果使用自定义编码器,请确保 IsContentTypeSupported 方法已正确实现。第一个 1024 响应的字节数是:...
有谁知道我如何使用 WCF 客户端(不使用 HttpWebRequest 类)使用此多部分/相关消息?是否有适用于此场景的配置?
【问题讨论】:
-
您是否尝试从
text切换到Mtom来编码SOAP 消息?配置:<binding messageEncoding="Mtom">/代码:binding.MessageEncoding = WSMessageEncoding.Mtom; -
是的,它似乎没有改变任何东西。 (我会将绑定信息添加到我的问题中)
标签: c# java wcf response content-type