Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BalanceInquiry : System.Web.Services.WebService
- {
- [WebMethod]
- public string getAccount(string accNbr)
- {
- return accNbr;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- //creating object of program class to access methods
- Program obj = new Program();
- Console.WriteLine("Please Enter Input values..");
- //Reading input values from console
- string a =(Console.ReadLine());
- // int b = Convert.ToInt32(Console.ReadLine());
- //Calling InvokeService method
- obj.InvokeService(a);
- }
- public void InvokeService(string a )
- {
- //Calling CreateSOAPWebRequest method
- HttpWebRequest request = CreateSOAPWebRequest();
- XmlDocument SOAPReqBody = new XmlDocument();
- //SOAP Body Request
- 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>");
- using (Stream stream = request.GetRequestStream())
- {
- using (StreamWriter stmw = new StreamWriter(stream))
- {
- stmw.Write(SOAPReqBody);
- }
- }
- try
- {
- //Geting response from request
- WebResponse response = request.GetResponse();
- }
- catch (WebException e)
- {
- Console.WriteLine(e.ToString());
- }
- Console.Read();
- // Stream responseStream = response.GetResponseStream();
- //using (WebResponse Serviceres = request.GetResponse())
- //{
- // using (StreamReader rd = new StreamReader(Serviceres.GetResponseStream()))
- // {
- // //reading stream
- // var ServiceResult = rd.ReadToEnd();
- // //writting stream result on console
- // Console.WriteLine(ServiceResult);
- // Console.ReadLine();
- // }
- //}
- }
- public HttpWebRequest CreateSOAPWebRequest()
- {
- //Making Web Request
- HttpWebRequest Req = (HttpWebRequest)WebRequest.Create("http://localhost:20483/balanceinquiry.asmx");
- //SOAPAction
- Req.Headers.Add("SOAPAction:http://tempuri.org/Addition");
- //Content_type
- Req.ContentType = "text/xml;charset="utf-8"";
- Req.Accept = "text/xml";
- //HTTP method
- Req.Method = "POST";
- //return HttpWebRequest
- return Req;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement