可能的SOAP版本不匹配:信封命名空间 - C#中的SAP Web服务

时间:2017-10-24 04:50:54

标签: c# web-services soap

我的要求是通过SOAMANAGER创建的SAP Web服务将C#连接到SAP。

我已关注此博客 - https://blogs.sap.com/2013/03/08/create-an-sap-web-service-call-web-service-from-net-application-passing-user-credentials/

当我执行代码时,我收到以下异常消息。

An unhandled exception of type 'System.Web.Services.Protocols.SoapException' 
occurred in System.Web.Services.dll

Additional information: Possible SOAP version mismatch: Envelope namespace 
http://schemas.xmlsoap.org/wsdl/ was unexpected. Expecting 
http://schemas.xmlsoap.org/soap/envelope/.

这是我的C#代码:

 NetworkCredential cred = new NetworkCredential();
        cred.UserName = "XXXXX";
        cred.Password = "*****";
        HELLO_WORLD_2_WSDL.z_HELLO_WORLD_2 hello_world = new HELLO_WORLD_2_WSDL.z_HELLO_WORLD_2();
        HELLO_WORLD_2_WSDL.ZTEST_WEB_SERVICE hello_world_input = new HELLO_WORLD_2_WSDL.ZTEST_WEB_SERVICE();
        HELLO_WORLD_2_WSDL.ZTEST_WEB_SERVICEResponse hello_world_response = new HELLO_WORLD_2_WSDL.ZTEST_WEB_SERVICEResponse();
        hello_world.Proxy = new WebProxy("domain", 8000);
        hello_world.PreAuthenticate = true;
        hello_world.Credentials = cred;
        hello_world_response = hello_world.ZTEST_WEB_SERVICE(hello_world_input);
        Console.WriteLine(hello_world_response.ToString());

这是通过SOAMANAGER创建的WSDL代码:

  <?xml version="1.0" encoding="utf8" ?> 
  <wsdl:definitions targetNamespace="urn:sapcom:document:sap:rfc:functions" 
  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
  xmlns:wsoap12="http://schemas.xmlsoap.org/wsdl/soap12/" 
  xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" 
  xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" 
  xmlns:tns="urn:sapcom:document:sap:rfc:functions" 
  xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
  <wsdl:documentation>
  <sidl:sidl xmlns:sidl="http://www.sap.com/2007/03/sidl" /> 
  </wsdl:documentation>
  <wsp:UsingPolicy wsdl:required="true" /> 
  <wsp:Policy wsu:Id="BN__Z_HELLO_WORLD_2">
 <wsp:Policy wsu:Id="IF__Z_hello_world_2">
 <wsp:ExactlyOne>
 <wsp:All>

 <wsp:Policy wsu:Id="OP__ZTEST_WEB_SERVICE">
 <wsp:ExactlyOne>
 <wsp:All>
  </wsp:ExactlyOne>
  </wsp:Policy>
 <wsdl:types>
 <xsd:schema attributeFormDefault="qualified" targetNamespace="urn:sapcom:document:sap:rfc:functions">
 <xsd:simpleType name="char20">
 <xsd:restriction base="xsd:string">
  <xsd:maxLength value="20" /> 
  </xsd:restriction>
  </xsd:simpleType>
 <xsd:element name="ZTEST_WEB_SERVICE">
 <xsd:complexType>
  <xsd:sequence /> 
  </xsd:complexType>
  </xsd:element>
 <xsd:element name="ZTEST_WEB_SERVICEResponse">
 <xsd:complexType>
 <xsd:sequence>
  <xsd:element name="O_MSG" type="tns:char20" /> 
  </xsd:sequence>
  </xsd:complexType>
  </xsd:element>
  </xsd:schema>
  </wsdl:types>
 <wsdl:message name="ZTEST_WEB_SERVICE">
  <wsdl:part name="parameters" element="tns:ZTEST_WEB_SERVICE" /> 
  </wsdl:message>
 <wsdl:message name="ZTEST_WEB_SERVICEResponse">
  <wsdl:part name="parameter" element="tns:ZTEST_WEB_SERVICEResponse" /> 
  </wsdl:message>
 <wsdl:portType name="Z_hello_world_2">
 <wsp:Policy>
  <wsp:PolicyReference URI="#IF__Z_hello_world_2" /> 
  </wsp:Policy>
 <wsdl:operation name="ZTEST_WEB_SERVICE">
 <wsp:Policy>
  <wsp:PolicyReference URI="#OP__ZTEST_WEB_SERVICE" /> 
  </wsp:Policy>
  <wsdl:input message="tns:ZTEST_WEB_SERVICE" /> 
  <wsdl:output message="tns:ZTEST_WEB_SERVICEResponse" /> 
  </wsdl:operation>
  </wsdl:portType>
 <wsdl:binding name="Z_HELLO_WORLD_2" type="tns:Z_hello_world_2">
 <wsp:Policy>
  <wsp:PolicyReference URI="#BN__Z_HELLO_WORLD_2" /> 
  </wsp:Policy>
  <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" /> 
 <wsdl:operation name="ZTEST_WEB_SERVICE">
  <soap:operation soapAction="urn:sapcom:document:sap:rfc:functions:Z_hello_world_2:ZTEST_WEB_SERVICERequest" style="document" /> 
 <wsdl:input>
  <soap:body use="literal" /> 
  </wsdl:input>
 <wsdl:output>
  <soap:body use="literal" /> 
  </wsdl:output>
  </wsdl:operation>
  </wsdl:binding>
 <wsdl:binding name="Z_HELLO_WORLD_2_soap12" type="tns:Z_hello_world_2">
 <wsp:Policy>
  <wsp:PolicyReference URI="#BN__Z_HELLO_WORLD_2_soap12" /> 
  </wsp:Policy>
  <wsoap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" /> 
 <wsdl:operation name="ZTEST_WEB_SERVICE">
  <wsoap12:operation soapAction="urn:sapcom:document:sap:rfc:functions:Z_hello_world_2:ZTEST_WEB_SERVICERequest" style="document" /> 
 <wsdl:input>
  <wsoap12:body use="literal" /> 
  </wsdl:input>
 <wsdl:output>
  <wsoap12:body use="literal" /> 
  </wsdl:output>
  </wsdl:operation>
  </wsdl:binding>
 <wsdl:service name="z_HELLO_WORLD_2">
 <wsdl:port name="Z_HELLO_WORLD_2" binding="tns:Z_HELLO_WORLD_2">
  <soap:address location="http://domainXXX:8000/sap/bc/srt/rfc/sap/z_hello_world_2/199/z_hello_world_2/z_hello_world_2" /> 
  </wsdl:port>
 <wsdl:port name="Z_HELLO_WORLD_2_soap12" binding="tns:Z_HELLO_WORLD_2_soap12">
  <wsoap12:address location="http://domainXXX:8000/sap/bc/srt/rfc/sap/z_hello_world_2/199/z_hello_world_2/z_hello_world_2" /> 
  </wsdl:port>
  </wsdl:service>
      </wsdl:definitions>

这里我缩短了我的XML代码,因为它的大小很大。 请帮助任何人解决这个问题。

1 个答案:

答案 0 :(得分:0)

我在SAP中创建Web服务时,通过将配置文件更改为使用用户和密码进行身份验证,无传输保证解决了上述问题,并在SOAMANAGER中将传输通道身份验证更改为用户ID /密码。

Transport Method

C#:更改App.Config中的绑定URL

解决了我的上述问题。