c# - Web 服务的空响应 (WSDL SOAP)

标签 c# web-services soap xsd wsdl

我正在使用 Visual Studio 2008 C# Windows 应用程序连接到由外部公司创建的 Web 服务。该服务是一个 WSDL url,它是一个基本的 soap 请求和响应。我已将该服务导入为服务引用。我可以调用该服务,并且没有收到任何错误,但没有任何响应。在 Fiddler 中监视 soap 请求和响应时,我看到一个响应返回,但好像 VS 无法解释该响应。我查看过创建 xsd,但收到一条错误消息,指出已经存在架构。所以我完全不知所措。我希望有人能帮帮忙。如果之前已经解决了这个确切的问题,我深表歉意,但我找不到任何可以解决我的问题的方法。

提前致谢!

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

 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>

fiddler响应如下:

<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>cn=webgateway@poc-aaa,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>

最佳答案

感谢您发布由 Fiddler 收集的回复。实际上,我在 WSDL 和对 WSDL 数据类型的响应一致性中看到了不止一个问题。

第一期:WSDL 一致性/完整性

请注意,输入和输出消息分别指的是 tns:DownloadShipmentDataV001tns:DownloadShipmentDataV001Responsexmlns:tns="http://schemas.ccc.com/AROPInventory/bpm/external" 是消息定义上下文中的相关prefix:namespace 绑定(bind),因此,请求和响应消息元素的完全限定名称是 {http://schemas.ccc.com/AROPInventory/bpm/external}DownloadShipmentDataV001{http://schemas. ccc.com/AROPInventory/bpm/external}分别下载ShipmentDataV001Response

凭借 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 和任何导入/包含的文档中缺少消息定义中引用的实际类型。

stub 生成器在尝试使用 WSDL 时应该提示这一点。

外部公司应该真正纠正这个问题,但是您可以复制 WSDL 并通过从类型部分声明实际元素的 namespace 并绑定(bind)到前缀,然后在消息定义中使用该前缀来进行调整(弱点因为您有一个额外的步骤来跟上他们服务定义的任何变化):

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>

第二个问题:Response Message Does Not Match Schema

假设 WSDL 是一致的,并且从类型部分调用了完全限定的数据类型。响应消息的完全限定元素结构将类似于:

{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 类型部分中声明为元素,也未从其他文档导入。如果 unmarshaller 使用 WSDL 中提供的数据类型定义,它不理解 ShipmentHeader 或其子元素,因此可能会将它们排除在外(如您所见)。

此问题的更正是将数据类型架构定义与服务的实际响应相匹配。同样,托管该服务的外部组织应该更正此问题(他们的服务不符合给定的 WSDL),但您可以再次在本地进行调整,但要注意额外的步骤,使“您的”wsdl 与他们的服务保持同步。

我希望这对您有所帮助并回答更多问题。

关于c# - Web 服务的空响应 (WSDL SOAP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11738936/

相关文章:

c# - 将数据客户端发布到服务器 C# 的最佳方式

wcf - 带有 rest 和 soap 端点的真实世界示例 wcf

c# - 运算符 |= 在 C# 中是什么意思?

c# - 在通用中查找速度

javascript - Service Worker 和页面权限

wcf - 使用消息安全性时的 WS-Security 开销

java - Spring Boot Soap 集成测试失败

ruby-on-rails - 我可以使用 httparty 或 weary 使用 SOAP 网络服务吗?

c# - 如何使用 & 对 XML 字符串进行编码

c# - JsonSerializer 不包含 Parse 的定义