Not showing data from SOAP service

送分小仙女□ 提交于 2019-12-10 00:23:30

问题


I have an interesting problem involving a C# console client and a web service. My suspicion is that there is a name space error somewhere or something simple, but eight hours of staring blankly into the screen has yet to reveal them so I thought I'd try a few more eyes.

WSDL

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://
schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
xmlns:schema="http://xxx.com/BillOfMaterials/schemas" xmlns:tns="http://
xxx.com/BillOfMaterials/definitions"
targetNamespace="http://xxx.com/BillOfMaterials/definitions">
    <wsdl:types>
        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <xs:import namespace="http://xxx.com/BillOfMaterials/
schemas" schemaLocation="BOMRequest.xsd" id="input"/>

    <xs:import namespace="http://xxx.com/BillOfMaterials/schemas" 
schemaLocation="BOMResponse.xsd" id="output"/>
        </xs:schema>
    </wsdl:types>
    <wsdl:message name="BomRequest">
        <wsdl:part name="input" element="schema:BOMin"/>
    </wsdl:message>
    <wsdl:message name="BomResponse">
        <wsdl:part name="output" element="schema:BOMResponse"/>
    </wsdl:message>
    <wsdl:portType name="BOMPortType">
        <wsdl:operation name="BOM">
            <wsdl:input message="tns:BomRequest"/>
            <wsdl:output message="tns:BomResponse"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="BOMBinding" type="tns:BOMPortType">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/
http"/>
        <wsdl:operation name="BOM">
            <soap:operation soapAction="urn:#BOMOperation"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="BOMService">
        <wsdl:port name="BOMPort" binding="tns:BOMBinding">
            <soap:address location="http://xxx/BOM"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

Request XSD

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/
XMLSchema" xmlns:in="http://secotools.com/BillOfMaterials/schemas" 
targetNamespace="http://xxx.com/BillOfMaterials/schemas" elementFormDefault="qualified">
    <xs:element name="BOMin" type="in:BOMRequestItem"/>
    <xs:complexType name="BOMRequestItem">
        <xs:sequence>
            <xs:element name="ProductNumber" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
</xs:schema>

Response XSD (shortened as it's well large)

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/
XMLSchema" xmlns:in="http://xxx.com/BillOfMaterials/schemas" 
targetNamespace="http://xxx.com/BillOfMaterials/schemas" 
elementFormDefault="qualified">
    <xs:element name="BOMResponse">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="BOMResponses" type="in:BOMResponseItem" 
minOccurs="0" maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:complexType name="BOMResponseItem">
        <xs:sequence>
            <xs:element name="Company" type="xs:string"/>
            <xs:element name="Facility" type="xs:string"/>
            <xs:element name="ProductNumber" type="xs:string"/>
            <xs:element name="ProductStructureType" type="xs:string"/>
            <xs:element name="Name" type="xs:string"/>

Using this WSDL I get the following request and response in soapUI: SoapUI request:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:sch="http://xxx.com/BillOfMaterials/schemas">
   <soapenv:Header/>
   <soapenv:Body>
      <sch:BOMin>
         <ProductNumber>12345</ProductNumber>
      </sch:BOMin>
   </soapenv:Body>
</soapenv:Envelope>

SoapUI response (shortened for readability):

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:out="http://xxx.com/BillOfMaterials/schemas">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
      <out:BOMResponse>
         <Company>1</Company>
         <Facility>1</Facility>
         <ProductNumber>12345</ProductNumber>
         <ProductStructureType>PLU</ProductStructureType>
         <Name>My dummy product</Name>

I've tried both generating a proxy with svcutil and used a service reference in C# to no avail. SoapUI works as expected and returns data while C# get an empty list.

C# test code

class Program
{
    static void Main(string[] args)
    {
        BOMPortTypeClient _client = new BOMPortTypeClient();
        var state = _client.State;
        BOMRequestItem _reqItem = new BOMRequestItem
        {
            ProductNumber = "12345"
        };

        IList<BOMResponseItem> _list = _client.BOM(_reqItem);
    }
}

Edit: Added Fiddler logs with request/response from .Net

.Net request

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <BOMin xmlns="http://xxx.com/BillOfMaterials/schemas">
       <ProductNumber>12345</ProductNumber>
    </BOMin>
  </s:Body>
</s:Envelope>

.Net response

<?xml version="1.0" ?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://xxx.com/BillOfMaterials/schemas" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <s:Header/>
   <s:Body>
      <BOMResponse>
         <Company>1</Company>
         <Facility>1</Facility>
         <ProductNumber>12345</ProductNumber>
         <ProductStructureType>PLU</ProductStructureType>
         <Name>My dummy product</Name>

Since I do get data back I know the service understands the request from .Net, problem is .Net seems unable to understand the response. This is why I thought at first it was a namespace issue. Now I'm not so sure anymore. I get no errors in .Net, just an empty array.

来源:https://stackoverflow.com/questions/8485744/not-showing-data-from-soap-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!