Facebook
From Gamboge Cheetah, 1 Year ago, written in C#.
This paste is a reply to XML from HarryPalheta - view diff
Embed
Download Paste or View Raw
Hits: 116
  1. using System;
  2. using System.Net;
  3. using System.Text.RegularExpressions;
  4.  
  5.  
  6. namespace Program
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string url = "http://10.162.4.245/OA30FFKIWCF.svc?wsdl";
  13.             string soapRequest = @"<soap:Envelope xmlns:soap=""http://www.w3.org/2003/05/soap-envelope"" xmlns:tem=""http://tempuri.org/"">
  14.                                   <soap:Header xmlns:wsa=""http://www.w3.org/2005/08/addressing""> <wsa:To>http://10.162.4.245/OA30FFKIWCF.svc</wsa:To>
  15.                                   <wsa:Action>http://tempuri.org/IOA30FFKIWCF/GetDPKStatusByWIP_SN</wsa:Action> </soap:Header>
  16.                                   <soap:Body> <tem:GetDPKStatusByWIP_SN> <!--Optional:--> <tem:WIP_SN>4003189900003</tem:WIP_SN> </tem:GetDPKStatusByWIP_SN>
  17.                                   </soap:Body></soap:Envelope>";
  18.  
  19.             WebClient webClient = new WebClient();
  20.  
  21.             webClient.Headers.Add("Content-Type", "application/soap+xml;charset=UTF-8;action=\"http://tempuri.org/IOA30FFKIWCF/GetDPKStatusByWIP_SN\"");
  22.  
  23.             try
  24.             {
  25.                 // Call the SOAP API and get the response
  26.                 string soapResult = webClient.UploadString(url, soapRequest);
  27.                 // Parse the SOAP response and get the query
  28.                 Regex ER = new Regex(@"\<b:ProductKeyStateID>.*</b:ProductKeyStateID>", RegexOptions.None);
  29.                 var match = "";
  30.                 if (ER.IsMatch(soapResult))
  31.  
  32.                 {
  33.  
  34.                     match = ER.Match(soapResult).Value.ToString();
  35.  
  36.                 }
  37.                 var result = Regex.Match(match, @"[\d]").Value;
  38.                 return result;
  39.  
  40.             }
  41.             catch (Exception ex)
  42.             {
  43.                 Console.WriteLine("Error: " + ex.Message);
  44.             }
  45.         }
  46.     }
  47. }