C#Soap客户端没有填充响应中的所有元素

时间:2015-10-01 02:29:01

标签: java c# web-services soap

您好我正在开发一个简单的c#控制台应用程序来从Java JAX-WS服务获取信息。我已经得到了我的应用程序来调用服务并获取信息,但由于某种原因,响应不会填充所有属性。我已经验证了我期待的所有内容都会在回复中回来,而且我认为我没有像目前为止看过的其他问题一样存在名称空间问题。

这是我的实际Soap Response,我正在填充fileDate,但fileName始终为null。

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns2:getExtractDateResponse xmlns:ns2="http://endpoint.data_extracts_ws.example.com/">
         <dataExtractDateModel>
            <fileDate>2015-09-17T00:00:00-05:00</fileDate>
            <fileName>export_file.zip</fileName>
         </dataExtractDateModel>
      </ns2:getExtractDateResponse>
   </S:Body>
</S:Envelope>

这是我的控制台应用

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataExtractsServiceClient.DataExtractsService;

namespace DataExtractsServiceClient
{
    class Program
    {
        static void Main(string[] args)
        {
            DataExtractsEndpointClient extractService = new DataExtractsEndpointClient();
            extractService.ClientCredentials.UserName.UserName = "my_username";
            extractService.ClientCredentials.UserName.Password = "my_password";
            DataExtractDateModel extractDateModel = extractService.getExtractDate("EXTRACT_NAME");
            System.Console.WriteLine("File Name Is " + extractDateModel.fileName);
            System.Console.WriteLine("File Date Is " + extractDateModel.fileDate);
            System.Console.WriteLine("Finished");
            System.Console.ReadLine();
        }
    }
}

和App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
    </startup>
    <system.serviceModel>
        <bindings>
            <customBinding>
                <binding name="DataExtractsEndpointPortBinding">
                    <!--    WsdlImporter encountered unrecognized policy assertions in ServiceDescription 'http://endpoint.data_extracts_ws.example.com/':    -->
                    <!--    <wsdl:binding name='DataExtractsEndpointPortBinding'>    -->
                    <!--        <wsoma:OptimizedMimeSerialization xmlns:wsoma="http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization">..</wsoma:OptimizedMimeSerialization>    -->
                    <mtomMessageEncoding messageVersion="Soap11" />
                    <httpsTransport authenticationScheme="Basic"/>
                </binding>
            </customBinding>
        </bindings>
        <client>
            <endpoint address="https://example.com/data_extracts_ws/DataExtractsEndpointService"
                binding="customBinding" bindingConfiguration="DataExtractsEndpointPortBinding"
                contract="DataExtractsService.DataExtractsEndpoint" name="DataExtractsEndpointPort" />
        </client>
    </system.serviceModel>
</configuration>

添加XSD和WSDL

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:tns="http://endpoint.data_extracts_ws.example.com/" targetNamespace="http://endpoint.data_extracts_ws.example.com/" version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="ExtractException" type="tns:ExtractException" />
  <xs:element name="ExtractNotFoundException" type="tns:ExtractNotFoundException" />
  <xs:element name="getExtract" type="tns:getExtract" />
  <xs:element name="getExtractDate" type="tns:getExtractDate" />
  <xs:element name="getExtractDateResponse" type="tns:getExtractDateResponse" />
  <xs:element name="getExtractResponse" type="tns:getExtractResponse" />
  <xs:complexType name="ExtractException">
    <xs:sequence>
      <xs:element minOccurs="0" name="message" type="xs:string" />
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="ExtractNotFoundException">
    <xs:sequence>
      <xs:element minOccurs="0" name="message" type="xs:string" />
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="getExtract">
    <xs:sequence>
      <xs:element name="extractName" type="xs:string" />
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="getExtractResponse">
    <xs:sequence>
      <xs:element xmlns:ns1="http://www.w3.org/2005/05/xmlmime" minOccurs="0" name="dataExtractModel" type="tns:DataExtractModel" />
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="DataExtractModel">
    <xs:sequence>
      <xs:element minOccurs="0" name="fileName" type="xs:string" />
      <xs:element minOccurs="0" name="fileData" type="xs:base64Binary" />
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="getExtractDate">
    <xs:sequence>
      <xs:element name="extractName" type="xs:string" />
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="getExtractDateResponse">
    <xs:sequence>
      <xs:element minOccurs="0" name="dataExtractDateModel" type="tns:DataExtractDateModel" />
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="DataExtractDateModel">
    <xs:sequence>
      <xs:element minOccurs="0" name="fileName" type="xs:string" />
      <xs:element minOccurs="0" name="fileDate" type="xs:dateTime" />
    </xs:sequence>
  </xs:complexType>
</xs:schema>

<?xml version="1.0" encoding="utf-8"?>
<WL5G3N2:definitions xmlns:WL5G3N3="http://endpoint.data_extracts_ws.example.com/" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:WL5G3N1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:WL5G3N4="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:WL5G3N0="http://schemas.xmlsoap.org/ws/2004/09/policy" name="DataExtractsEndpointService" targetNamespace="http://endpoint.data_extracts_ws.example.com/" xmlns:WL5G3N2="http://schemas.xmlsoap.org/wsdl/">
  <WL5G3N0:Policy WL5G3N1:Id="Mtom.xml">
    <wsoma:OptimizedMimeSerialization xmlns:wsoma="http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization" />
  </WL5G3N0:Policy>
  <wsp:UsingPolicy WL5G3N2:Required="true" />
  <wsp:UsingPolicy WL5G3N2:Required="true" />
  <WL5G3N2:types>
    <xsd:schema xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://endpoint.data_extracts_ws.example.com/" xmlns:wssutil="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <xsd:import schemaLocation="https://www.example.com:443/data_extracts_ws/DataExtractsEndpointService?SCHEMA%2FData+Extracts+Service%2Fxsd%2FData+Extracts+Service+XSD" namespace="http://endpoint.data_extracts_ws.example.com/" />
    </xsd:schema>
  </WL5G3N2:types>
  <WL5G3N2:message name="getExtract">
    <WL5G3N2:part name="parameters" element="WL5G3N3:getExtract" />
  </WL5G3N2:message>
  <WL5G3N2:message name="getExtractResponse">
    <WL5G3N2:part name="parameters" element="WL5G3N3:getExtractResponse" />
  </WL5G3N2:message>
  <WL5G3N2:message name="ExtractException">
    <WL5G3N2:part name="fault" element="WL5G3N3:ExtractException" />
  </WL5G3N2:message>
  <WL5G3N2:message name="ExtractNotFoundException">
    <WL5G3N2:part name="fault" element="WL5G3N3:ExtractNotFoundException" />
  </WL5G3N2:message>
  <WL5G3N2:message name="getExtractDate">
    <WL5G3N2:part name="parameters" element="WL5G3N3:getExtractDate" />
  </WL5G3N2:message>
  <WL5G3N2:message name="getExtractDateResponse">
    <WL5G3N2:part name="parameters" element="WL5G3N3:getExtractDateResponse" />
  </WL5G3N2:message>
  <WL5G3N2:portType name="DataExtractsEndpoint">
    <WL5G3N2:operation name="getExtract">
      <WL5G3N2:input message="WL5G3N3:getExtract" />
      <WL5G3N2:output message="WL5G3N3:getExtractResponse" />
      <WL5G3N2:fault name="ExtractException" message="WL5G3N3:ExtractException" />
      <WL5G3N2:fault name="ExtractNotFoundException" message="WL5G3N3:ExtractNotFoundException" />
    </WL5G3N2:operation>
    <WL5G3N2:operation name="getExtractDate">
      <WL5G3N2:input message="WL5G3N3:getExtractDate" />
      <WL5G3N2:output message="WL5G3N3:getExtractDateResponse" />
      <WL5G3N2:fault name="ExtractException" message="WL5G3N3:ExtractException" />
      <WL5G3N2:fault name="ExtractNotFoundException" message="WL5G3N3:ExtractNotFoundException" />
    </WL5G3N2:operation>
  </WL5G3N2:portType>
  <WL5G3N2:binding name="DataExtractsEndpointPortBinding" type="WL5G3N3:DataExtractsEndpoint">
    <wsp:Policy>
      <wsp:PolicyReference URI="#Mtom.xml" />
      <wsp:PolicyReference URI="#Mtom.xml" />
    </wsp:Policy>
    <WL5G3N4:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <WL5G3N2:operation name="getExtract">
      <WL5G3N4:operation soapAction="" />
      <WL5G3N2:input>
        <WL5G3N4:body use="literal" />
      </WL5G3N2:input>
      <WL5G3N2:output>
        <WL5G3N4:body use="literal" />
      </WL5G3N2:output>
      <WL5G3N2:fault name="ExtractException">
        <WL5G3N4:fault use="literal" name="ExtractException" namespace="" />
      </WL5G3N2:fault>
      <WL5G3N2:fault name="ExtractNotFoundException">
        <WL5G3N4:fault use="literal" name="ExtractNotFoundException" namespace="" />
      </WL5G3N2:fault>
    </WL5G3N2:operation>
    <WL5G3N2:operation name="getExtractDate">
      <WL5G3N4:operation soapAction="" />
      <WL5G3N2:input>
        <WL5G3N4:body use="literal" />
      </WL5G3N2:input>
      <WL5G3N2:output>
        <WL5G3N4:body use="literal" />
      </WL5G3N2:output>
      <WL5G3N2:fault name="ExtractException">
        <WL5G3N4:fault use="literal" name="ExtractException" namespace="" />
      </WL5G3N2:fault>
      <WL5G3N2:fault name="ExtractNotFoundException">
        <WL5G3N4:fault use="literal" name="ExtractNotFoundException" namespace="" />
      </WL5G3N2:fault>
    </WL5G3N2:operation>
  </WL5G3N2:binding>
  <WL5G3N2:service name="DataExtractsEndpointService">
    <WL5G3N2:port name="DataExtractsEndpointPort" binding="WL5G3N3:DataExtractsEndpointPortBinding">
      <WL5G3N4:address location="https://www.example.com:443/data_extracts_ws/DataExtractsEndpointService" />
    </WL5G3N2:port>
  </WL5G3N2:service>
</WL5G3N2:definitions>

1 个答案:

答案 0 :(得分:0)

只是想回来并回答这个问题以防其他人有这个问题。问题是Weblogic生成的XSD的元素顺序与SOAP响应的顺序不同。 Java似乎没有问题,但C#确实存在问题。在这种情况下,XSD首先有文件名,文件日期为DataExtractDateModel。当我改变订单时,它开始工作。