我正在利用第三方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