Possibilities to include a SOAP interface in C# WinForm.

asked 2021-10-07T15:47:17.873+00:00
Markus Freitag 2,936 Reputation points

Hello,

What is the best way to create a SOAP request in C#?
Can i simulate the answers? If so, what is the best way?
Can I ask the customer if they have a WSDL file. Would it be easier then? Such a file, can it be created easily? I don't know, never done it before.

How would I have to include it in my C# WinForms, desktop project?

Do you have a sample code for me. THANKS.

//Request
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pdc="http://xmlns.oracle.com/orav/P/PDME">
       <soapenv:Header/>
       <soapenv:Body>
          <pdc:SELECT_ORDERInput>
             <pdc:P_IN-REQUEST_CONTAINER-CIN>
                <pdc:REQUEST_CONTAINER>
                   <pdc:MESSAGEID>F7DE84C6-9999-8888-831F-9ED3D8CF9E1B</pdc:MESSAGEID>
                   <pdc:TIMESTAMP>2021-10-07T09:25:00.063+02:00</pdc:TIMESTAMP>
                   <pdc:INTERFACEID>IF0001</pdc:INTERFACEID>
                   <pdc:REQ_DATA>
                      <pdc:SITE>B551</pdc:SITE>
                      <pdc:AREA>225S</pdc:AREA>
                      <pdc:EQUIP_NAME>LMWQWQW01</pdc:EQUIP_NAME>
                      <pdc:SHOP_ORDER>1522451680</pdc:SHOP_ORDER>
                   </pdc:REQ_DATA>
                </pdc:REQUEST_CONTAINER>
             </pdc:P_IN-REQUEST_CONTAINER-CIN>
             <pdc:P_OUT-LME_SEL_RESP-COUT/>
          </pdc:SELECT_ORDERInput>
       </soapenv:Body>
    </soapenv:Envelope>

//Response
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <SELECT_ORDEROutput xmlns="http://xmlns.oracle.com/orav/P/PDME">
         <P_OUT>
            <LME_SEL_RESP>
               <MESSAGEID>F7DE84C6-9999-8888-831F-9ED3D8CF9E1B</MESSAGEID>
               <TIMESTAMP>2021-10-07T11:28:21.618+02:00</TIMESTAMP>
               <INTERFACEID>IFSSS0001</INTERFACEID>
               <PROCESSINGSTATUS>
                  <RETURNVALUE>1</RETURNVALUE>
                  <RETURNCODE>0</RETURNCODE>
                  <RETURNDESCRIPTION/>
               </PROCESSINGSTATUS>
               <RESPONSE_DATA>
                  <EQUIP_NAME>LMWQWQW01</EQUIP_NAME>
                  <SHOP_ORDER>1522451680</SHOP_ORDER>
                  <WORKCENTER>12EEEQ5S</WORKCENTER>
                  <RELEASE_STAMP>2021-09-03T12:18:21.618+02:00</RELEASE_STAMP>
                  <ORDER_PRIORITY>5030</ORDER_PRIORITY>
                  <QUANTITY>2</QUANTITY>
                  <ISSUE>5</ISSUE>
                  <REVISION>7,</REVISION>
                  <PANEL_LIST>
                     <LME_SEL_PANEL>
                        <PANEL_ID>130eeB744112346G123</PANEL_ID>
                        <PRODUCTGROUP_ID>15451680_130B7441123456G123</PRODUCTGROUP_ID>
                        <BLOCK_LIST>
                           <LME_SEL_BLOCK>
                              <BLOCK_ID>PA</BLOCK_ID>
                              <BARCODE>130645671123</BARCODE>
                              <INFO_TEXT>130B74423</INFO_TEXT>
                           </LME_SEL_BLOCK>
                           <LME_SEL_BLOCK>
                              <BLOCK_ID>AA</BLOCK_ID>
                              <BARCODE>13066744112323</BARCODE>
                              <INFO_TEXT>130B74411235123</INFO_TEXT>
                           </LME_SEL_BLOCK>
                        </BLOCK_LIST>
                     </LME_SEL_PANEL>
                     <LME_SEL_PANEL>
                        <PANEL_ID>130ffB744156G123</PANEL_ID>
                        <PRODUCTGROUP_ID>15451680_130B74411123</PRODUCTGROUP_ID>
                        <BLOCK_LIST>
                           <LME_SEL_BLOCK>
                              <BLOCK_ID>PA</BLOCK_ID>
                              <BARCODE>16744112375671123</BARCODE>
                              <INFO_TEXT>130B7423756G123</INFO_TEXT>
                           </LME_SEL_BLOCK>
                        </BLOCK_LIST>
                     </LME_SEL_PANEL>
                  </PANEL_LIST>
               </RESPONSE_DATA>
            </LME_SEL_RESP>
         </P_OUT>
      </SELECT_ORDEROutput>
   </soap:Body>
</soap:Envelope>
.NET
.NET
Microsoft Technologies based on the .NET software framework.
598 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
6,911 questions
{count} votes

1 answer

Sort by: Most helpful
  1. answered 2021-10-13T17:41:31.247+00:00
    Castorix31 65,246 Reputation points

    You can use HttpWebRequest
    A test with the game LOTRO, WSDL : https://gls.lotro.com/GLS.DataCenterServer/Service.asmx?WSDL
    where I send the command GetDatacenters (in "SOAPAction") to get a list of LOTRO servers :

    HttpWebRequest httpWebRequest = ((HttpWebRequest)(WebRequest.Create("https://gls.lotro.com/GLS.DataCenterServer/Service.asmx")));
    httpWebRequest.Method = "POST";
    string sPostData = @"<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">
        <soap:Body>
            <GetDatacenters xmlns=""http://www.turbine.com/SE/GLS"">
                <game>LOTRO</game>
            </GetDatacenters>
        </soap:Body>
    </soap:Envelope>";
    byte[] byteArray = Encoding.UTF8.GetBytes(sPostData);
    // httpWebRequest.ContentType = "application/x-www-form-urlencoded";
    httpWebRequest.ContentType = "text/xml; charset=utf-8";
    httpWebRequest.ContentLength = byteArray.Length;
    httpWebRequest.UserAgent = "Test";
    Stream dataStream = httpWebRequest.GetRequestStream();
    dataStream.Write(byteArray, 0, byteArray.Length);
    dataStream.Close();
    
    httpWebRequest.Headers.Add(HttpRequestHeader.AcceptEncoding, "txt");
    // httpWebRequest.Headers.Add(HttpRequestHeader.UserAgent, "Test");
    httpWebRequest.Headers.Add("SOAPAction", "http://www.turbine.com/SE/GLS/GetDatacenters");
    
    WebResponse webResp = httpWebRequest.GetResponse();
    Console.WriteLine("Web response : {0}",((HttpWebResponse)(webResp)).StatusDescription);
    using (Stream str = webResp.GetResponseStream())
    {
        StreamReader streamReader = new StreamReader(str);
        string responseFromServer = streamReader.ReadToEnd();
        Console.WriteLine(responseFromServer);
    }
    webResp.Close();