Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java C#Soap客户端未填充响应中的所有元素_Java_C#_Web Services_Soap - Fatal编程技术网

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

Java C#Soap客户端未填充响应中的所有元素,java,c#,web-services,soap,Java,C#,Web Services,Soap,大家好,我正在开发一个简单的c#控制台应用程序,用于从Java JAX-WS服务获取信息。我已经让我的应用程序调用服务并获取信息,但由于某些原因,响应并没有填充所有属性。我已经验证了我所期望的一切都会返回到响应中,并且我不认为我已经遇到了名称空间问题,就像我已经查看过的其他问题一样 这是我实际的Soap响应,我很好地填充了fileDate,但fileName总是空的 <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/

大家好,我正在开发一个简单的c#控制台应用程序,用于从Java JAX-WS服务获取信息。我已经让我的应用程序调用服务并获取信息,但由于某些原因,响应并没有填充所有属性。我已经验证了我所期望的一切都会返回到响应中,并且我不认为我已经遇到了名称空间问题,就像我已经查看过的其他问题一样

这是我实际的Soap响应,我很好地填充了fileDate,但fileName总是空的

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


我只是想回来回答这个问题,以防其他人有这个问题。问题在于Weblogic生成的XSD的元素顺序与SOAP响应不同。Java似乎没有问题,但C有问题。在本例中,对于DataExtractDateModel,XSD的文件名第一,文件日期第二。当我切换订单时,它开始工作。

我建议您安装并使用SoapUI。使用SoapUI使用WSDL并测试调用,以查看响应是否正确填充。至少这将确认这是您的应用程序(.Net)还是Java服务的某些问题。我已经这样做了。上面的反应是通过Fiddler直接捕捉到的。
<?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>