Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. public class BalanceInquiry : System.Web.Services.WebService
  2. {
  3.  
  4. [WebMethod]
  5. public string getAccount(string accNbr)
  6. {
  7. return accNbr;
  8.  
  9. }
  10. }
  11.  
  12. class Program
  13. {
  14. static void Main(string[] args)
  15. {
  16. //creating object of program class to access methods
  17. Program obj = new Program();
  18. Console.WriteLine("Please Enter Input values..");
  19. //Reading input values from console
  20. string a =(Console.ReadLine());
  21. // int b = Convert.ToInt32(Console.ReadLine());
  22. //Calling InvokeService method
  23. obj.InvokeService(a);
  24.  
  25. }
  26. public void InvokeService(string a )
  27. {
  28. //Calling CreateSOAPWebRequest method
  29. HttpWebRequest request = CreateSOAPWebRequest();
  30.  
  31. XmlDocument SOAPReqBody = new XmlDocument();
  32. //SOAP Body Request
  33. SOAPReqBody.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?><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> <HelloWorld xmlns=""http://tempuri.org/""> </HelloWorld ></soap:Body></soap:Envelope>");
  34.  
  35.  
  36. using (Stream stream = request.GetRequestStream())
  37. {
  38. using (StreamWriter stmw = new StreamWriter(stream))
  39. {
  40. stmw.Write(SOAPReqBody);
  41. }
  42. }
  43.  
  44. try
  45. {
  46. //Geting response from request
  47. WebResponse response = request.GetResponse();
  48. }
  49.  
  50. catch (WebException e)
  51. {
  52. Console.WriteLine(e.ToString());
  53.  
  54. }
  55. Console.Read();
  56.  
  57. // Stream responseStream = response.GetResponseStream();
  58.  
  59. //using (WebResponse Serviceres = request.GetResponse())
  60. //{
  61. // using (StreamReader rd = new StreamReader(Serviceres.GetResponseStream()))
  62. // {
  63. // //reading stream
  64. // var ServiceResult = rd.ReadToEnd();
  65. // //writting stream result on console
  66. // Console.WriteLine(ServiceResult);
  67. // Console.ReadLine();
  68. // }
  69. //}
  70. }
  71.  
  72. public HttpWebRequest CreateSOAPWebRequest()
  73. {
  74. //Making Web Request
  75. HttpWebRequest Req = (HttpWebRequest)WebRequest.Create("http://localhost:20483/balanceinquiry.asmx");
  76. //SOAPAction
  77. Req.Headers.Add("SOAPAction:http://tempuri.org/Addition");
  78. //Content_type
  79. Req.ContentType = "text/xml;charset="utf-8"";
  80. Req.Accept = "text/xml";
  81. //HTTP method
  82. Req.Method = "POST";
  83. //return HttpWebRequest
  84. return Req;
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement