【问题标题】:How can a WCF client consume a multipart/related java webservice reponse?WCF 客户端如何使用多部分/相关的 Java Web 服务响应?
【发布时间】: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 消息?配置:&lt;binding messageEncoding="Mtom"&gt;/代码:binding.MessageEncoding = WSMessageEncoding.Mtom;
  • 是的,它似乎没有改变任何东西。 (我会将绑定信息添加到我的问题中)

标签: c# java wcf response content-type


【解决方案1】:

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

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

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

你还可以定义更多的配置,例如messageVersion。

【讨论】:

  • 太棒了,正是我想要的。如果您尝试使用 Oracle ADF 服务,并通过代理这样做,它们可能会成功,但 .NET 将引发有关响应类型的异常。以编程方式执行此操作 ([binding].MessageEncoding = WSMessageEncoding.Mtom;) 解决了我的问题。
  • @Tor 你是如何设置 MessageEncoding 的?你还有代码吗?对于 Mtom 绑定,我只看到 readerQuotas 和 writeEncoding。你使用 customBinding 还是 wsHttpBinding?
【解决方案2】:

我认为将系统转换为 MTOM 可以解决这个问题。

【讨论】:

  • 嗨,Mehmet,我也希望如此,但如果我将 messageEncoding="Mtom" 添加到 ,它不会改变任何事情