title: .NET consume SAP web service
body: <p>I'm trying to figure out how to consume a SAP webservice. I have a .WSDL file which looks for certain info in SAP. </p>
  
  <p><strong>My .WSDL file:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;wsdl:definitions name="Customer_Out" targetNamespace="..." xmlns:p1="...." xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"&gt;
      &lt;wsdl:documentation/&gt;
      &lt;wsp:UsingPolicy wsdl:required="true"/&gt;
      &lt;wsp:Policy wsu:Id="OP_CustomerRead_sync"/&gt;
      &lt;wsdl:types&gt;
          &lt;xsd:schema targetNamespace="..." xmlns="..." xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
              &lt;xsd:element name="MT_CustomerRead_response" type="DT_CustomerRead_response"/&gt;
              &lt;xsd:element name="FMT_Customer"&gt;
                  &lt;xsd:complexType&gt;
                      &lt;xsd:sequence&gt;
                          &lt;xsd:element name="standard" type="ExchangeFaultData"/&gt;
                      &lt;/xsd:sequence&gt;
                  &lt;/xsd:complexType&gt;
              &lt;/xsd:element&gt;
              &lt;xsd:element name="MT_CustomerRead_request" type="DT_CustomerRead_request"/&gt;
              &lt;xsd:complexType name="ExchangeFaultData"&gt;
                  &lt;xsd:annotation&gt;
                      &lt;xsd:appinfo source="http://sap.com/xi/VersionID"&gt;..&lt;/xsd:appinfo&gt;
                  &lt;/xsd:annotation&gt;
                  &lt;xsd:sequence&gt;
                      &lt;xsd:element name="faultText" type="xsd:string"/&gt;
                      &lt;xsd:element name="faultUrl" type="xsd:string" minOccurs="0"/&gt;
                      &lt;xsd:element name="faultDetail" type="ExchangeLogData" minOccurs="0" maxOccurs="unbounded"/&gt;
                  &lt;/xsd:sequence&gt;
              &lt;/xsd:complexType&gt;
              &lt;xsd:complexType name="DT_Customer"&gt;
                  &lt;xsd:annotation&gt;
                      &lt;xsd:appinfo source="http://sap.com/xi/VersionID"&gt;...&lt;/xsd:appinfo&gt;
                  &lt;/xsd:annotation&gt;
                  &lt;xsd:sequence&gt;
                      &lt;xsd:element name="BpId" type="xsd:string"&gt;
                          &lt;xsd:annotation&gt;
                              &lt;xsd:appinfo source="http://sap.com/xi/TextID"&gt;...&lt;/xsd:appinfo&gt;
                          &lt;/xsd:annotation&gt;
                      &lt;/xsd:element&gt;
                      &lt;xsd:element name="Name" type="xsd:string"&gt;
                          &lt;xsd:annotation&gt;
                              &lt;xsd:appinfo source="http://sap.com/xi/TextID"&gt;...&lt;/xsd:appinfo&gt;
                          &lt;/xsd:annotation&gt;
                      &lt;/xsd:element&gt;
                      &lt;xsd:element name="AccountGroup" type="xsd:string" minOccurs="0"&gt;
                          &lt;xsd:annotation&gt;
                              &lt;xsd:appinfo source="http://sap.com/xi/TextID"&gt;...&lt;/xsd:appinfo&gt;
                          &lt;/xsd:annotation&gt;
                      &lt;/xsd:element&gt;
                      &lt;xsd:element name="Street" type="xsd:string" minOccurs="0"&gt;
                          &lt;xsd:annotation&gt;
                              &lt;xsd:appinfo source="http://sap.com/xi/TextID"&gt;...&lt;/xsd:appinfo&gt;
                          &lt;/xsd:annotation&gt;
                      &lt;/xsd:element&gt;
                      &lt;xsd:element name="Number" type="xsd:string" minOccurs="0"&gt;
                          &lt;xsd:annotation&gt;
                              &lt;xsd:appinfo source="http://sap.com/xi/TextID"&gt;...&lt;/xsd:appinfo&gt;
                          &lt;/xsd:annotation&gt;
                      &lt;/xsd:element&gt;
                      &lt;xsd:element name="City" type="xsd:string" minOccurs="0"&gt;
                          &lt;xsd:annotation&gt;
                              &lt;xsd:appinfo source="http://sap.com/xi/TextID"&gt;...&lt;/xsd:appinfo&gt;
                          &lt;/xsd:annotation&gt;
                      &lt;/xsd:element&gt;
                      &lt;xsd:element name="Country" type="xsd:string" minOccurs="0"&gt;
                          &lt;xsd:annotation&gt;
                              &lt;xsd:appinfo source="http://sap.com/xi/TextID"&gt;...&lt;/xsd:appinfo&gt;
                          &lt;/xsd:annotation&gt;
                      &lt;/xsd:element&gt;
                      &lt;xsd:element name="Region" type="xsd:string" minOccurs="0"/&gt;
                  &lt;/xsd:sequence&gt;
              &lt;/xsd:complexType&gt;
              &lt;xsd:complexType name="DT_CustomerRead_request"&gt;
                  &lt;xsd:annotation&gt;
                      &lt;xsd:appinfo source="http://sap.com/xi/VersionID"&gt;...&lt;/xsd:appinfo&gt;
                  &lt;/xsd:annotation&gt;
                  &lt;xsd:sequence&gt;
                      &lt;xsd:element name="RowLimit" type="xsd:integer"/&gt;
                      &lt;xsd:element name="BpId" minOccurs="0"&gt;
                          &lt;xsd:annotation&gt;
                              &lt;xsd:appinfo source="http://sap.com/xi/TextID"&gt;...&lt;/xsd:appinfo&gt;
                          &lt;/xsd:annotation&gt;
                          &lt;xsd:simpleType&gt;
                              &lt;xsd:restriction base="xsd:string"&gt;
                                  &lt;xsd:maxLength value="10"/&gt;
                              &lt;/xsd:restriction&gt;
                          &lt;/xsd:simpleType&gt;
                      &lt;/xsd:element&gt;
                      &lt;xsd:element name="Name" type="xsd:string" minOccurs="0"&gt;
                          &lt;xsd:annotation&gt;
                              &lt;xsd:appinfo source="http://sap.com/xi/TextID"&gt;...&lt;/xsd:appinfo&gt;
                          &lt;/xsd:annotation&gt;
                      &lt;/xsd:element&gt;
                      &lt;xsd:element name="ExternalCustomer" type="xsd:string" minOccurs="0"&gt;
                          &lt;xsd:annotation&gt;
                              &lt;xsd:appinfo source="http://sap.com/xi/TextID"&gt;...&lt;/xsd:appinfo&gt;
                          &lt;/xsd:annotation&gt;
                      &lt;/xsd:element&gt;
                      &lt;xsd:element name="AccountGroup" type="xsd:string" minOccurs="0"&gt;
                          &lt;xsd:annotation&gt;
                              &lt;xsd:appinfo source="http://sap.com/xi/TextID"&gt;...&lt;/xsd:appinfo&gt;
                          &lt;/xsd:annotation&gt;
                      &lt;/xsd:element&gt;
                  &lt;/xsd:sequence&gt;
              &lt;/xsd:complexType&gt;
              &lt;xsd:complexType name="ExchangeLogData"&gt;
                  &lt;xsd:annotation&gt;
                      &lt;xsd:appinfo source="http://sap.com/xi/VersionID"&gt;...&lt;/xsd:appinfo&gt;
                  &lt;/xsd:annotation&gt;
                  &lt;xsd:sequence&gt;
                      &lt;xsd:element name="severity" type="xsd:string" minOccurs="0"/&gt;
                      &lt;xsd:element name="text" type="xsd:string"/&gt;
                      &lt;xsd:element name="url" type="xsd:string" minOccurs="0"/&gt;
                      &lt;xsd:element name="id" type="xsd:string" minOccurs="0"/&gt;
                  &lt;/xsd:sequence&gt;
              &lt;/xsd:complexType&gt;
              &lt;xsd:complexType name="DT_CustomerRead_response"&gt;
                  &lt;xsd:annotation&gt;
                      &lt;xsd:appinfo source="http://sap.com/xi/VersionID"&gt;...&lt;/xsd:appinfo&gt;
                  &lt;/xsd:annotation&gt;
                  &lt;xsd:sequence&gt;
                      &lt;xsd:element name="Customer" type="DT_Customer" minOccurs="0" maxOccurs="unbounded"&gt;
                          &lt;xsd:annotation&gt;
                              &lt;xsd:appinfo source="http://sap.com/xi/TextID"&gt;...&lt;/xsd:appinfo&gt;
                          &lt;/xsd:annotation&gt;
                      &lt;/xsd:element&gt;
                      &lt;xsd:element name="Remark" type="xsd:string" minOccurs="0"/&gt;
                  &lt;/xsd:sequence&gt;
              &lt;/xsd:complexType&gt;
          &lt;/xsd:schema&gt;
      &lt;/wsdl:types&gt;
      &lt;wsdl:message name="MT_CustomerRead_request"&gt;
          &lt;wsdl:documentation/&gt;
          &lt;wsdl:part name="MT_CustomerRead_request" element="p1:MT_CustomerRead_request"/&gt;
      &lt;/wsdl:message&gt;
      &lt;wsdl:message name="MT_CustomerRead_response"&gt;
          &lt;wsdl:documentation/&gt;
          &lt;wsdl:part name="MT_CustomerRead_response" element="p1:MT_CustomerRead_response"/&gt;
      &lt;/wsdl:message&gt;
      &lt;wsdl:message name="FMT_Customer"&gt;
          &lt;wsdl:documentation/&gt;
          &lt;wsdl:part name="FMT_Customer" element="p1:FMT_Customer"/&gt;
      &lt;/wsdl:message&gt;
      &lt;wsdl:portType name="Customer_Out"&gt;
          &lt;wsdl:documentation/&gt;
          &lt;wsdl:operation name="CustomerRead_sync"&gt;
              &lt;wsdl:documentation/&gt;
              &lt;wsp:Policy&gt;
                  &lt;wsp:PolicyReference URI="#OP_CustomerRead_sync"/&gt;
              &lt;/wsp:Policy&gt;
              &lt;wsdl:input message="p1:MT_CustomerRead_request"/&gt;
              &lt;wsdl:output message="p1:MT_CustomerRead_response"/&gt;
              &lt;wsdl:fault name="FMT_Customer" message="p1:FMT_Customer"/&gt;
          &lt;/wsdl:operation&gt;
      &lt;/wsdl:portType&gt;
      &lt;wsdl:binding name="Customer_OutBinding" type="p1:Customer_Out"&gt;
          &lt;soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/&gt;
          &lt;wsdl:operation name="CustomerRead_sync"&gt;
              &lt;soap:operation soapAction="http://sap.com/xi/WebService/soap1.1" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/&gt;
              &lt;wsdl:input&gt;
                  &lt;soap:body use="literal" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/&gt;
              &lt;/wsdl:input&gt;
              &lt;wsdl:output&gt;
                  &lt;soap:body use="literal" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/&gt;
              &lt;/wsdl:output&gt;
              &lt;wsdl:fault name="FMT_Customer"&gt;
                  &lt;soap:fault use="literal" name="FMT_Customer" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/&gt;
              &lt;/wsdl:fault&gt;
          &lt;/wsdl:operation&gt;
      &lt;/wsdl:binding&gt;
      &lt;wsdl:service name="Customer_OutService"&gt;
          &lt;wsdl:port name="HTTP_Port" binding="p1:Customer_OutBinding"&gt;
              &lt;soap:address location="..." xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/&gt;
          &lt;/wsdl:port&gt;        
      &lt;/wsdl:service&gt;
  &lt;/wsdl:definitions&gt;
  </code></pre>
  
  <p>I've added a Service Reference to my .NET project which references the .WSDL file. This creates a namespace which allows me to make an instance of a couple of classes (9 in total).</p>
  
  <p>I can't seem to find how to pass the request and receive the corresponding response. Should I parse these requests/responses? I'm aware of <a href="http://www.c-sharpcorner.com/uploadfile/chinnasrihari/consming-sap-web-services-and-net/" rel="nofollow">this</a> tutorial but it doesn't really correspond with the file which I'm dealing with.</p>
  
  <p>A request looks like this:</p>
  
  <pre><code>&lt;man:MT_CustomerRead_request&gt;
           &lt;RowLimit&gt;100&lt;/RowLimit&gt;
           &lt;!--Optional:--&gt;
           &lt;!-- &lt;CustomerId&gt;?
           &lt;!--Optional:--&gt;
           &lt;Name&gt;Dell*&lt;/Name&gt;
           &lt;!--Optional:--&gt;
           &lt;!--Optional:--&gt;
           &lt;AccountGroup&gt;ABC&lt;/AccountGroup&gt;
  &lt;/man:MT_CustomerRead_request&gt;
  </code></pre>
  
  <p>Thanks in advance</p>