2012-07-31 173 views
3

我正在使用Visual Studio 2008 C#Windows应用程序连接到由外部公司创建的Web服务。该服务是一个WSDL URL,它是一个基本的SOAP请求和响应。我将这项服务引入了服务参考。我可以打电话给这个服务,并且不会收到任何错误,但是这个回应没有任何意义。当在Fiddler中监控肥皂请求和响应时,我看到一个响应回来,但它好像VS不能解释响应。我已经着眼于创建xsd,但得到一个错误,指出已经有一个模式。所以我处于全面亏损状态。我希望有人能帮帮忙。我很抱歉,如果这个确切的问题之前已经解决,但我找不到任何解决我的问题。Web服务(WSDL SOAP)的空响应

在此先感谢!

我使用到连接到服务的代码如下:

ServiceReference1.bpm bbb = new TestingWSDL.ServiceReference1.bpm(); 

     ServiceReference1.BPMExternalAppServicesV001Client soapClient = new TestingWSDL.ServiceReference1.BPMExternalAppServicesV001Client(); 

     ServiceReference1.DownloadShipmentDataV001 req = new TestingWSDL.ServiceReference1.DownloadShipmentDataV001(); 
     ServiceReference1.DownloadShipmentDataV001Response resp = new TestingWSDL.ServiceReference1.DownloadShipmentDataV001Response(); 

     try 
     { 

      soapClient.DownloadShipmentDataV001(req,out resp); 

     } 
     catch(Exception err) 
     { 
      MessageBox.Show(err.Message); 
     } 

响应对象不具有任何数据我不能发布的图像,因为我不允许的。

的WSDL是很长,如下:

<?xml version="1.0" encoding="utf-8"?> 
<wsdl:definitions xmlns:tns="http://schemas.ccc.com/AROPInventory/bpm/external" xmlns:inst="http://schemas.aaa.com/bpm/instance/1.0" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="BPMExternalAppServicesV001" targetNamespace="http://schemas.ccc.com/AROPInventory/bpm/external" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"> 
    <wsdl:types> 
    <xsd:schema xmlns:tns1="http://schemas.ccc.com/AROPInventory/bpm/external" xmlns="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://schemas.argility.com/AROPInventory/bpm/external" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
     <xsd:import namespace="http://schemas.aaa.com/bpm/instance/1.0" /> 
     <xsd:element name="UploadShipmentDataV001"> 
     <xsd:complexType> 
      <xsd:sequence> 
      <xsd:element ref="tns1:Shipments" /> 
      </xsd:sequence> 
     </xsd:complexType> 
     </xsd:element> 
     <xsd:element xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" name="Shipments"> 
     <xsd:complexType> 
      <xsd:sequence> 
      <xsd:element minOccurs="0" maxOccurs="unbounded" name="Shipment"> 
       <xsd:complexType> 
       <xsd:sequence> 
        <xs:element name="ShipmentNumber" type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema" /> 
        <xsd:element name="Cartons"> 
        <xsd:complexType> 
         <xsd:sequence> 
         <xsd:element minOccurs="0" maxOccurs="unbounded" name="Carton"> 
          <xsd:annotation> 
          <xsd:documentation>0:not damaged 1:damaged 2: Rejected0:not damaged 1:damaged 2: Rejected0:not damaged 1:damaged 2: Rejected</xsd:documentation> 
          </xsd:annotation> 
          <xsd:complexType> 
          <xsd:sequence> 
           <xs:element name="CartionID" type="xs:byte" xmlns:xs="http://www.w3.org/2001/XMLSchema" /> 
           <xs:element name="Status" type="xs:byte" xmlns:xs="http://www.w3.org/2001/XMLSchema" /> 
          </xsd:sequence> 
          </xsd:complexType> 
         </xsd:element> 
         </xsd:sequence> 
        </xsd:complexType> 
        </xsd:element> 
       </xsd:sequence> 
       </xsd:complexType> 
      </xsd:element> 
      </xsd:sequence> 
     </xsd:complexType> 
     </xsd:element> 
     <xsd:element name="TestUploadShipMentV001"> 
     <xsd:complexType> 
      <xsd:sequence> 
      <xsd:element ref="tns1:Shipments" /> 
      </xsd:sequence> 
     </xsd:complexType> 
     </xsd:element> 
     <xsd:element name="TestUploadShipMentV001Response" /> 
     <xsd:element name="UploadShipmentDataV001Response" /> 
     <xsd:element name="DownloadShipmentDataV001"> 
     <xsd:complexType> 
      <xsd:sequence /> 
     </xsd:complexType> 
     </xsd:element> 
     <xsd:element name="DownloadShipmentDataV001Response"> 
     <xsd:complexType> 
      <xsd:sequence> 
      <xsd:element ref="tns1:Shipments" /> 
      </xsd:sequence> 
     </xsd:complexType> 
     </xsd:element> 
    </xsd:schema> 
    <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://schemas.aaa.com/bpm/instance/1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
     <xsd:element name="bpm"> 
     <xsd:complexType> 
      <xsd:sequence> 
      <xsd:element name="instance_id" type="xsd:string" /> 
      </xsd:sequence> 
     </xsd:complexType> 
     </xsd:element> 
    </xsd:schema> 
    </wsdl:types> 
    <wsdl:message name="DownloadShipmentDataV001Input"> 
    <wsdl:part name="body" element="tns:DownloadShipmentDataV001" /> 
    </wsdl:message> 
    <wsdl:message name="DownloadShipmentDataV001Output"> 
    <wsdl:part name="body" element="tns:DownloadShipmentDataV001Response" /> 
    </wsdl:message> 
    <wsdl:message name="HeaderOutput"> 
    <wsdl:part name="BPMHeader" element="inst:bpm" /> 
    </wsdl:message> 
    <wsdl:portType name="BPMExternalAppServicesV001"> 
    <wsdl:operation name="DownloadShipmentDataV001"> 
     <wsdl:input message="tns:DownloadShipmentDataV001Input" /> 
     <wsdl:output message="tns:DownloadShipmentDataV001Output" /> 
    </wsdl:operation> 
    </wsdl:portType> 
    <wsdl:binding name="BPMExternalAppServicesV001" type="tns:BPMExternalAppServicesV001"> 
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" /> 
    <wsdl:operation name="DownloadShipmentDataV001"> 
     <soap:operation soapAction="" style="document" /> 
     <wsdl:input> 
     <soap:body use="literal" /> 
     </wsdl:input> 
     <wsdl:output> 
     <soap:body use="literal" /> 
     <soap:header message="tns:HeaderOutput" part="BPMHeader" use="literal" /> 
     </wsdl:output> 
    </wsdl:operation> 
    </wsdl:binding> 
    <wsdl:service name="BPMExternalAppServicesV001Service"> 
    <wsdl:port name="BPMExternalAppServicesV001Port" binding="tns:BPMExternalAppServicesV001"> 
     <soap:address location="http://aaa/aaa/com.eibus.web.soap.Gateway.wcp?organization=o=system,cn=aaa,cn=aaa,o=ho.bbb.co.za" /> 
    </wsdl:port> 
    </wsdl:service> 
</wsdl:definitions> 

小提琴手答复如下:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
<s:Header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
    <header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" 
     xmlns="http://schemas.aaa.com/General/1.0/"> 
     <sender> 
      <reply-to> 
       cn=Business Process Management,cn=Business Process Management,cn=soap nodes,o=system,cn=aaa,cn=aaa20,o=ho.bbb.co.za 
      </reply-to> 
      <organizationalContext>o=system,cn=aaa,cn=aaa20,o=ho.bbb.co.za</organizationalContext> 
      <component>cn=Business Process Management,cn=soap nodes,o=system,cn=aaa,cn=aaa20,o=ho.bbb.co.za</component> 
     </sender> 
     <receiver> 
      <component>[email protected],cn=aaa,cn=aaa20,o=ho.bbb.co.za</component> 
      <sent-to xmlns="http://schemas.aaa.com/General/1.0/">socket://poc-aaa:20379/</sent-to> 
     </receiver> 
     <msg-id>00505680-004E-11E1-FBF1-7CB604BB1FC0</msg-id> 
    </header> 
    <bpm xmlns="http://schemas.aaa.com/bpm/instance/1.0"> 
     <instance_id>26c34038-bea4-459c-a0ad-86b462ae90cb</instance_id> 
    </bpm> 
</s:Header> 
<s:Body> 
    <DownloadShipmentDataV001Response xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.argility.com/AROPInventory/bpm/external"> 
     <Shipments xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.argility.com/AROPInventory/bpm/external"> 
      <ShipmentHeader> 
       <ShipmentNumber>S001</ShipmentNumber> 
       <ReceivingBranch>B000028</ReceivingBranch> 
       <SendingBranch>B000001</SendingBranch> 
       <ExpectedDate>2012/07/30</ExpectedDate> 
       <TotalNrOfCartons>2</TotalNrOfCartons> 
       <ShipmentStatus>E</ShipmentStatus> 
       <Cartons> 
        <Carton> 
         <CartonHeader> 
          <NrOfItems>2</NrOfItems> 
          <CartionID>99</CartionID> 
         </CartonHeader> 
         <CartonDetail> 
          <SKU>12345</SKU> 
          <Description>abc</Description> 
          <SerialNumber>6789</SerialNumber> 
          <QtySent>20</QtySent> 
          <QtyReceived/> 
         </CartonDetail> 
         <CartonDetail> 
          <SKU>12390</SKU> 
          <Description>abc</Description> 
          <SerialNumber>67232</SerialNumber> 
          <QtySent>2</QtySent> 
          <QtyReceived/> 
         </CartonDetail> 
        </Carton> 
        <Carton> 
         <CartonHeader> 
          <NrOfItems>2</NrOfItems> 
          <CartionID>100</CartionID> 
         </CartonHeader> 
         <CartonDetail> 
          <SKU>12345</SKU> 
          <Description>abc</Description> 
          <SerialNumber>6789</SerialNumber> 
          <QtySent>20</QtySent> 
          <QtyReceived/> 
         </CartonDetail> 
         <CartonDetail> 
          <SKU>12390</SKU> 
          <Description>abc</Description> 
          <SerialNumber>67232</SerialNumber> 
          <QtySent>2</QtySent> 
          <QtyReceived/> 
         </CartonDetail> 
        </Carton> 
       </Cartons> 
      </ShipmentHeader> 
      <ShipmentHeader> 
       <ShipmentNumber>S002</ShipmentNumber> 
       <ReceivingBranch>B000029</ReceivingBranch> 
       <SendingBranch>B000002</SendingBranch> 
       <ExpectedDate>2012/06/3</ExpectedDate> 
       <TotalNrOfCartons>21</TotalNrOfCartons> 
       <ShipmentStatus>E</ShipmentStatus> 
       <Cartons> 
        <Carton> 
         <CartonHeader> 
          <NrOfItems>3</NrOfItems> 
          <CartionID>91</CartionID> 
         </CartonHeader> 
         <CartonDetail> 
          <SKU>12345</SKU> 
          <Description>abc</Description> 
          <SerialNumber>6789</SerialNumber> 
          <QtySent>20</QtySent> 
          <QtyReceived/> 
         </CartonDetail> 
         <CartonDetail> 
          <SKU>12390</SKU> 
          <Description>abc</Description> 
          <SerialNumber>67232</SerialNumber> 
          <QtySent>2</QtySent> 
          <QtyReceived/> 
         </CartonDetail> 
        </Carton> 
        <Carton> 
         <CartonHeader> 
          <NrOfItems>1</NrOfItems> 
          <CartionID>97</CartionID> 
         </CartonHeader> 
         <CartonDetail> 
          <SKU>12390</SKU> 
          <Description>abc</Description> 
          <SerialNumber>67232</SerialNumber> 
          <QtySent>2</QtySent> 
          <QtyReceived/> 
         </CartonDetail> 
        </Carton> 
       </Cartons> 
      </ShipmentHeader> 
     </Shipments> 
    </DownloadShipmentDataV001Response> 
</s:Body> 
</s:Envelope> 
+0

如果您发布了在小提琴手中看到的回复,那么还有一点可以继续。一种可能性是来自Web服务的响应不是*完全*将在wsdl中指定的内容。这里常见的问题是名称空间不一致。您的解组器可能被配置为使用wsdl中的名称空间,并忽略来自不同namspace的响应元素。 – dcbyers 2012-08-04 21:22:25

+0

谢谢@dcbyers。我已将小提琴手回应加入原始问题 – 2012-08-06 06:27:23

回答

1

感谢由小提琴手所收集发布的响应。实际上,我在WSDL中看到了多个问题,并且响应与WSDL数据类型一致。

第一个问题:WSDL一致性/完整性

注意,输入和输出消息分别指tns:DownloadShipmentDataV001tns:DownloadShipmentDataV001Responsexmlns:tns="http://schemas.ccc.com/AROPInventory/bpm/external"是相关的前缀:名称空间绑定在消息定义的上下文中,因此请求和响应消息元素的完全限定名分别为{http://schemas.ccc.com/AROPInventory/bpm/external}DownloadShipmentDataV001{http://schemas.ccc.com/AROPInventory/bpm/external}DownloadShipmentDataV001Response

借助于targetNamespace="http://schemas.argility.com/AROPInventory/bpm/external"声明的,在WSDL文档的类型部分中定义的元素的完全合格的名称是 {http://schemas.argility.com/AROPInventory/bpm/external}DownloadShipmentDataV001{http://schemas.argility.com/AROPInventory/bpm/external}DownloadShipmentDataV001Response。这是一个问题,因为WSDL和任何导入/包含的文档中缺少消息定义中引用的实际类型。

存根生成器在尝试使用WSDL时应该抱怨这一点。

外部公司应该真正解决这个问题,但是您可以复制WSDL并进行调整,方法是从types部分声明实际元素的名称空间并绑定到前缀,然后在消息定义中使用该前缀弱点是你必须跟上他们的服务定义的任何更改)的额外步骤:

xmlns:fromtype="http://schemas.argility.com/AROPInventory/bpm/external" 
... 
    <wsdl:message name="DownloadShipmentDataV001Input"> 
    <wsdl:part name="body" element="fromtype:DownloadShipmentDataV001" /> 
    </wsdl:message> 
    <wsdl:message name="DownloadShipmentDataV001Output"> 
    <wsdl:part name="body" element="fromtype:DownloadShipmentDataV001Response" /> 
    </wsdl:message> 

第二期:响应消息不匹配模式

假设WSDL是一致的,并叫了完全合格的数据pe从类型部分。然后,响应消息的完全合格的元件结构,预计将是这样的:

{http://schemas.argility.com/AROPInventory/bpm/external}DownloadShipmentDataV001Response 
    {http://schemas.argility.com/AROPInventory/bpm/external}Shipments 
    {http://schemas.argility.com/AROPInventory/bpm/external}Shipment 
     {http://schemas.argility.com/AROPInventory/bpm/external}ShipmentNumber 
     {http://schemas.argility.com/AROPInventory/bpm/external}Cartons 
     {http://schemas.argility.com/AROPInventory/bpm/external}Carton 
... 

然而,在响应消息的实际结构是:

{http://schemas.argility.com/AROPInventory/bpm/external}DownloadShipmentDataV001Response 
    {http://schemas.argility.com/AROPInventory/bpm/external}Shipments 
    {http://schemas.argility.com/AROPInventory/bpm/external}ShipmentHeader 
     {http://schemas.argility.com/AROPInventory/bpm/external}ShipmentNumber 
... 

注意ShipmentHeader从来没有声明为元素在WSDL类型部分中,并且不从其他文档导入。如果解组器使用WSDL中提供的数据类型定义,那么它不理解ShipmentHeader或其子元素,因此可能会将其忽略(如您所见)。

此问题的更正是将数据类型模式定义与来自服务的实际响应进行匹配。同样,托管服务的外部组织应该纠正这种错误(他们的服务不符合给定的WSDL),但是您可以再次在本地进行调整,同时警告有关额外步骤,使您的wsdl与其服务锁定在一起。

我希望这可以帮助并回应更多的问题。

+0

非常感谢。我已经和其他一些更有知识的同事谈过了,并且他们同意我的答案。已经通过信息发送给创建服务的公司,他们会为我纠正服务。 – 2012-08-17 05:51:07

0

你仍然需要自己解析这个XML文件。

我们在IBM的Remedy软件中遇到类似的问题。基本上它是可怕的软件,这种行为应该是可以预料的。即使他们更新代码以匹配,他们也不会从他们正在生成的实际XML文档生成WSDL ...这个问题会一直持续下去,直到他们改变他们的方法,并且您无法控制。