我正在利用第三方Web服务返回带有使用MTOM编码附加PDF的对象。无法解析MTOM响应
该对象的结构为Data[]
,每个数组元素具有字段ContentType
和Include
。
当我运行web服务方法时,它完成请求罚款,但它没有正确解析响应,因为包含字段被解析为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响应:使用所提供的WSDL内置
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...
数据定义:
[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,那么只要您将消息编码设置为mtom,您就不需要解析,则附件将在响应对象中可用 –
您是否可以提供整个SOAP消息(或更好的是整个MIME消息除编码的附件?)另外,请提供相关的ServiceContract/DataContract定义。您需要确保您想要进行MTOM解码的DataMember的类型为byte []。 –
@EugeneOsovetsky我添加了SOAP响应和对象定义。我没有自己的数据联系人,我正在使用由WSDL构建的联系人。 – Victor