Click here to Skip to main content
15,849,678 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My requirement is connect C# to SAP through SAP Web service which created via SOAMANAGER.

when i executing the code i am getting the below Exception Message.

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/.


Here is my C# code:


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());


Here is WSDL Code created via SOAMANAGER:


HTML
<pre> <?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>


Here i have cut shorted my XML code because its size big. Please help anyone to solve this.


What I have tried:

I have tried the above code based this blog.https://blogs.sap.com/2013/03/08/create-an-sap-web-service-call-web-service-from-net-application-passing-user-credentials/
Posted
Updated 23-Oct-17 21:03pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900