Why would a WebService return nulls when the actual service returns data?
I have a webservice (out of my control) that I have to talk to. I also have a packet-sniffer on the line, and the developers of the webservice aren't lying. I see data in the correct fields.
They are actually sending back all of the data that I requested. But the web-service code that is auto-generated from the WSDL file is giving me "null" as a value.
UPDATE: For clarification, the object returned is NOT null. The elements within the object are null. I don't know if that will help anyone or not. I'm totally stumped.
I used their WSDL file to generate my Web Reference. I checked my data types with the datatypes that the WSDL file has declared. And I used the code as listed below to perform the calls:
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);
The resp object is an actual object. It was generated properly. However, the Status and MaterialData fields are always null.
When I call the web service, I've placed a packet-sniffer on the line, and I can see that I've sent the following (linebreaks and indentions for my own sanity):
<?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>
The response that they send back SEEMS to be a valid response (linebreaks and indentions for my own sanity):
<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>
The status shows that it actually received data... but the resp.Status and resp.MaterialData fields are always null. What have I done wrong?
UPDATE: The WSDL file is defined as:
<?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="MaterialN开发者_如何学Cumber" 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>
You'd have to post the WSDL for me to be sure, but "Web Service Returns Null" almost always means there's a dispute about XML Namespaces - the service is sending you data in one namespace, and .NET is expecting a different namespace.
In this case, note that most of the response is in the default namespace, even though the wrapper element is in the http://MyCompany.com/SomeCompany/mm/MaterialMasterSearch
namespace.
Make sure your service references are up to date. This happens to us when the service WSDL changed but the references were not updated.
精彩评论