无法分析MTOM响应

本文关键字:MTOM 响应 | 更新日期: 2023-09-27 18:20:08

我正在使用第三方web服务,该服务返回一个使用MTOM编码附加PDF的对象。

对象被构造为Data[],每个阵列元素具有字段ContentTypeInclude

当我运行web服务方法时,它很好地完成了请求,但它没有正确地解析响应,因为Include字段被解析为null

当我运行Fiddler时,我实际上可以看到远程web服务返回一个包含所有可用字段的响应。

这是SOAP中发送的内容:

<m:GetDocImageResponse>
    <x:data>
        <x:item xmime5:contentType="*/*">
        <xop:Include href="cid:id1"/></x:item>
    </x:data>
</m:GetDocImageResponse>

我看到Include具有名为href的属性,其中包含对二进制PDF文档的引用。

我正在尝试根据WSDL:解析对象

Data[] retObject = null;
using (blahWS ws = new blahWS())
{
 try{
retObject = ws.GetDoc(parameters); //request completes with no errors, but `Include` is parse as null
[...]
   }
catch
{..}
 }

web服务参考与简单的basicHttpBinding 一起使用

<basicHttpBinding>
    <binding name="BasicHTTPwithMTOM" messageEncoding="Mtom" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" textEncoding="utf-8" />        
</basicHttpBinding>

我应该以不同的方式解析响应吗?为什么它不解析字段?

编辑:

完整SOAP响应:

HTTP/1.1 200 OK
Server: gSOAP/2.7
Content-Type: multipart/related; charset=utf-8; boundary="==nGpzR/KspN6ry7jG8CU4bonN2aujzfJamyN3xYjaldFXYpeUryNGb0UROC0B=="; type="application/xop+xml"; start="<SOAP-ENV:Envelope>"; start-info="text/xml"
Content-Length: 180557
Connection: close
--==nGpzR/KspN6ry7jG8CU4bonN2aujzfJamyN3xYjaldFXYpeUryNGb0UROC0B==
Content-Type: application/xop+xml; charset=utf-8; type="text/xml"
Content-Transfer-Encoding: binary
Content-ID: <SOAP-ENV:Envelope>
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:xmime5="http://www.w3.org/2005/05/xmlmime" xmlns:m="http://www.mcleodsoftware.com/wsdl/ws4v.wsdl" xmlns:x="http://www.mcleodsoftware.com/schemas/ws4v.xsd">
<SOAP-ENV:Body>
    <m:GetDocImageResponse>
        <x:data>
            <x:item xmime5:contentType="*/*">
                <xop:Include href="cid:id1"/></x:item>
        </x:data>
    </m:GetDocImageResponse>
</SOAP-ENV:Body>

--==nGpzR/KspN6ry7jG8CU4bonN2aujzfJamyN3xYjaldFXYpeUryNGb0UROC0B==
Content-Type: */*
Content-Transfer-Encoding: binary
Content-ID: <id1>
...binary...

使用提供的WSDL构建的数据定义:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.233")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.mcleodsoftware.com/schemas/ws4v.xsd")]
public partial class Data : object, System.ComponentModel.INotifyPropertyChanged {
    private Include includeField;
    private string contentTypeField;
    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Namespace="http://www.w3.org/2004/08/xop/include", Order=0)]
    public Include Include {
        get {
            return this.includeField;
        }
        set {
            this.includeField = value;
            this.RaisePropertyChanged("Include");
        }
    }

无法分析MTOM响应

您的WSDL似乎显式地提供了元素的模式。我确信这是错误的,不符合标准。元素应声明为xsd:base64Binary类型(例如,请参阅https://wiki.duraspace.org/display/GSOC/MTOM+支持+on+the+WSDL+Level),并且还有其他符合标准的方法可以在您的WSDL中说明您正在使用MTOM(例如,请参阅http://www.w3.org/Submission/WS-MTOMPolicy/)

如果您将WSDL修复为符合标准(或者至少符合WCF期望的"MTOM WSDL"的外观),我认为一切都应该正常。实际上,如果您想了解一个合适的"MTOM WSDL"是什么样子的,只需首先在WCF中创建一个简单的MTOM服务代码即可。http://msdn.microsoft.com/en-us/library/aa395209.aspx-并查看它生成的WSDL和XSD。