Почему WebService возвращает нулевые значения, когда реальная служба возвращает данные? - PullRequest
5 голосов
/ 13 апреля 2010

У меня есть веб-сервис (вне моего контроля), с которым мне нужно поговорить. У меня также есть перехватчик пакетов, и разработчики веб-сервиса не лгут. Я вижу данные в правильных полях.

Они на самом деле отправляют обратно все данные, которые я запрашивал. Но код веб-службы, который автоматически генерируется из файла WSDL, дает мне значение «ноль» в качестве значения.

ОБНОВЛЕНИЕ: Для пояснения возвращаемый объект НЕ является нулевым. Элементы внутри объекта равны нулю. Я не знаю, поможет ли это кому-нибудь или нет. Я в полном замешательстве.

Я использовал их файл WSDL для генерации моей веб-ссылки. Я проверил свои типы данных с типами данных, которые объявил файл 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);

Соответственно объект является фактическим объектом. Сгенерировано правильно. Однако поля Status и MaterialData всегда имеют значение null.

Когда я вызываю веб-сервис, я помещаю анализатор пакетов в строку и вижу, что отправил следующее (разрывы строк и отступы для моего собственного здравого смысла):

<?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>

Ответ, который они отправляют обратно в SEEMS, чтобы быть действительным ответом (разрывы строк и отступы для моего здравомыслия):

<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>

Ответы [ 2 ]

6 голосов
/ 13 апреля 2010

Вы должны были бы опубликовать WSDL для меня, чтобы быть уверенным, но "Web Service Returns Null" почти всегда означает, что есть спор о пространствах имен XML - служба отправляет вам данные в одном пространстве имен, а .NET ожидает другое пространство имен.

В этом случае обратите внимание, что большая часть ответа находится в пространстве имен по умолчанию, даже если элемент оболочки находится в пространстве имен http://MyCompany.com/SomeCompany/mm/MaterialMasterSearch.

2 голосов
/ 13 апреля 2010

Убедитесь, что ваши сервисные ссылки актуальны. Это происходит с нами, когда служба WSDL изменилась, но ссылки не были обновлены.

...