我有一個web服務(不受我的控制),我必須與之交談。我也有一個包嗅探器在線,而web服務的開發人員並沒有說謊。我在正確的字段中看到數據。當實際服務返回數據時,爲什麼WebService會返回空值?
他們實際上發回我請求的所有數據。但是從WSDL文件自動生成的Web服務代碼給了我「空值」作爲值。
更新:爲了說明起見,返回的對象不是null。對象內的元素爲空。我不知道這是否會幫助任何人。我完全被難住了。
我用他們的WSDL文件來生成我的Web引用。我使用WSDL文件聲明的數據類型檢查了我的數據類型。我使用下面列出的代碼來執行呼叫:
DT_MaterialMaster_LookupRequest req = new DT_MaterialMaster_LookupRequest();
req.MaterialNumber = "101*";
req.DocumentNo = "";
req.Description = "Pipe*";
req.Plant = "0000";
MI_MaterialMaster_Lookup_OBService srv = new MI_MaterialMaster_Lookup_OBService();
DT_MaterialMaster_Response resp =
srv.MI_MaterialMaster_Lookup_OB(new DT_MaterialMaster_LookupRequest[] { req });
// Note that the response here is ALWAYS null!!
Console.WriteLine(resp.Status);
resp對象是一個實際的對象。它正確生成。但是,Status和MaterialData字段始終爲空。
當我調用web服務,我已經放在線路上的數據包嗅探器,我可以看到,我已經發下(我自己的理智和換行符的凹痕):
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<MT_MaterialMaster_Lookup
xmlns="http://MyCompany.com/SomeCompany/mm/MaterialMasterSearch">
<Request xmlns="">
<MaterialNumber>101*</MaterialNumber>
<Description>Pipe*</Description>
<DocumentNo />
<Plant>0000</Plant>
</Request>
</MT_MaterialMaster_Lookup>
</soap:Body>
</soap:Envelope>
,他們所發回的響應似乎是一個有效響應(換行符和我自己的理智凹痕):
<SOAP:Envelope xmlns:SOAP='http://schemas.xmlsoap.org/soap/envelope/'>
<SOAP:Header />
<SOAP:Body>
<n0:MT_MaterialMaster_Response
xmlns:n0='http://MyCompany.com/SomeCompany/mm/MaterialMasterSearch'
xmlns:prx='urn:SomeCompany.com:proxy:BRD:/1SAI/TAS4FE14A2DE960D61219AE:701:2009/02/10'>
<Response>
<Status>No Rows Found</Status>
<MaterialData />
</Response>
</n0:MT_MaterialMaster_Response>
</SOAP:Body>
</SOAP:Envelope>
狀態表明,實際收到的資料......但resp.Status和resp.MaterialData字段始終爲空。我做錯了什麼?
UPDATE: WSDL文件的定義是:
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:p1="http://MyCompany.com/SomeCompany/mm/MaterialMasterSearch" name="MI_MaterialMaster_Lookup_OB" targetNamespace="http://MyCompany.com/SomeCompany/mm/MaterialMasterSearch" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<xsd:schema xmlns="http://MyCompany.com/SomeCompany/mm/MaterialMasterSearch"
targetNamespace="http://MyCompany.com/SomeCompany/mm/MaterialMasterSearch"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="MT_MaterialMaster_Response" type="p1:DT_MaterialMaster_Response" />
<xsd:element name="MT_MaterialMaster_Lookup" type="p1:DT_MaterialMaster_Lookup" />
<xsd:complexType name="DT_MaterialMaster_Response">
<xsd:sequence>
<xsd:element name="Status" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://SomeCompany.com/xi/TextID">d48d03b040af11df99e300145eccb24e</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element maxOccurs="unbounded" name="MaterialData">
<xsd:annotation>
<xsd:appinfo source="http://SomeCompany.com/xi/TextID">64908aa040a511df843700145eccb24e</xsd:appinfo>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:element name="MaterialNumber" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://SomeCompany.com/xi/TextID">64908aa140a511df848500145eccb24e</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element minOccurs="0" name="Description" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://SomeCompany.com/xi/TextID">64908aa240a511df95bf00145eccb24e</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element minOccurs="0" name="DocumentNo" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://SomeCompany.com/xi/TextID">64908aa340a511dfb23700145eccb24e</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element minOccurs="0" name="UOM" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://SomeCompany.com/xi/TextID">3b5f14c040a611df9fbe00145eccb24e</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element minOccurs="0" name="Hierarchy" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://SomeCompany.com/xi/TextID">64908aa440a511dfc65b00145eccb24e</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element minOccurs="0" name="Plant" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://SomeCompany.com/xi/TextID">d48d03b140af11dfb78e00145eccb24e</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element minOccurs="0" name="Procurement" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://SomeCompany.com/xi/TextID">d48d03b240af11dfb87b00145eccb24e</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="DT_MaterialMaster_Lookup">
<xsd:sequence>
<xsd:element maxOccurs="unbounded" name="Request">
<xsd:annotation>
<xsd:appinfo source="http://SomeCompany.com/xi/TextID">64908aa040a511df843700145eccb24e</xsd:appinfo>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:element minOccurs="0" name="MaterialNumber" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://SomeCompany.com/xi/TextID">64908aa140a511df848500145eccb24e</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element minOccurs="0" name="Description" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://SomeCompany.com/xi/TextID">64908aa240a511df95bf00145eccb24e</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element minOccurs="0" name="DocumentNo" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://SomeCompany.com/xi/TextID">64908aa340a511dfb23700145eccb24e</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element minOccurs="0" name="Plant" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://SomeCompany.com/xi/TextID">64908aa440a511dfc65b00145eccb24e</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
<wsdl:message name="MT_MaterialMaster_Lookup">
<wsdl:part name="MT_MaterialMaster_Lookup" element="p1:MT_MaterialMaster_Lookup" />
</wsdl:message>
<wsdl:message name="MT_MaterialMaster_Response">
<wsdl:part name="MT_MaterialMaster_Response" element="p1:MT_MaterialMaster_Response" />
</wsdl:message>
<wsdl:portType name="MI_MaterialMaster_Lookup_OB">
<wsdl:operation name="MI_MaterialMaster_Lookup_OB">
<wsdl:input message="p1:MT_MaterialMaster_Lookup" />
<wsdl:output message="p1:MT_MaterialMaster_Response" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="MI_MaterialMaster_Lookup_OBBinding" type="p1:MI_MaterialMaster_Lookup_OB">
<binding transport="http://schemas.xmlsoap.org/soap/http" xmlns="http://schemas.xmlsoap.org/wsdl/soap/" />
<wsdl:operation name="MI_MaterialMaster_Lookup_OB">
<operation soapAction="http://SomeCompany.com/xi/WebService/soap1.1" xmlns="http://schemas.xmlsoap.org/wsdl/soap/" />
<wsdl:input>
<body use="literal" xmlns="http://schemas.xmlsoap.org/wsdl/soap/" />
</wsdl:input>
<wsdl:output>
<body use="literal" xmlns="http://schemas.xmlsoap.org/wsdl/soap/" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="MI_MaterialMaster_Lookup_OBService">
<wsdl:port name="MI_MaterialMaster_Lookup_OBPort" binding="p1:MI_MaterialMaster_Lookup_OBBinding">
<address location="http://bxdwas.MyCompany.com/XISOAPAdapter/MessageServlet?channel=:SOAP_SND_Material_Lookup" xmlns="http://schemas.xmlsoap.org/wsdl/soap/" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
好主意......我碰過你的答案,因爲這是一個很好的選擇。但是,我可以僞造一個數據包,並僞造他們的數據包,並在各處更改名稱空間。這似乎不是問題。它不會崩潰,並且對象本身不是NULL。對象內的項目爲空。 – Jerry 2010-04-14 14:35:32
@Jerry:我會嘗試在午餐時更詳細地看看這一點 - 但我不得不說,WSDL並不會顯示通常表示混合命名空間的符號。與此同時,如果您可以查看您的Reference.cs文件並查看哪些名稱空間已放置在元素上,並與XML進行比較,那就太好了。 – 2010-04-14 17:31:22
與開發人員合作,讓他們給我一個新的WSDL。 (你發誓我要求他們發送政府機密)。最終明白了,你不知道,這是不同的。顯然,每個項目現在是一個項目的數組,而不是一個項目,因此爲什麼它是空的...... .NET無法確定類型,所以它留空。 – Jerry 2010-04-14 18:44:26