Calling webservice
-
I am newbie to webservices I am trying to learn about them, but got struck in the first place itself. Please help me out. My service.cs in the web service. --------------------------------
using System; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; [WebService(Namespace = "http://localhost:1458/forumservices/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class Service : System.Web.Services.WebService { public Service () { //Uncomment the following line if using designed components //InitializeComponent(); } [WebMethod] public string welcome(string name) { return "Welcome " + name; } }
now on a button click from another web pageprotected void Button1_Click(object sender, EventArgs e) { try { soapMessage = @" <?xml version=""1.0"" encoding=""utf-8""?> <soap12:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap12=""http://www.w3.org/2003/05/soap-envelope""> <soap12:Body> <welcome xmlns=""http://localhost:1458/forumservices/""> <name>Rajas</name> </welcome> </soap12:Body> </soap12:Envelope>"; WebClient mClient = new WebClient(); Response.Write(System.Text.Encoding.ASCII.GetString(mClient.UploadData("http://localhost:1458/forumservices/Service.asmx", "POST", System.Text.Encoding.ASCII.GetBytes(soapMessage)))); } catch (System.Net.WebException ex) { if (ex.Response != null) { Stream strm = ex.Response.GetResponseStream(); StreamReader sr = new StreamReader(strm); Response.Write(sr.ReadToEnd()); } else { Response.Write(ex.InnerException.ToString()); } } }
The compilation is fine, but i keep getting some errors as below "The remote server returned an error: (500) Internal Server Error." Please help me outJack Sparrow -------------------------------------- Defeat is not the worst of failures. Not to have tried is the true failure.
-
I am newbie to webservices I am trying to learn about them, but got struck in the first place itself. Please help me out. My service.cs in the web service. --------------------------------
using System; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; [WebService(Namespace = "http://localhost:1458/forumservices/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class Service : System.Web.Services.WebService { public Service () { //Uncomment the following line if using designed components //InitializeComponent(); } [WebMethod] public string welcome(string name) { return "Welcome " + name; } }
now on a button click from another web pageprotected void Button1_Click(object sender, EventArgs e) { try { soapMessage = @" <?xml version=""1.0"" encoding=""utf-8""?> <soap12:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap12=""http://www.w3.org/2003/05/soap-envelope""> <soap12:Body> <welcome xmlns=""http://localhost:1458/forumservices/""> <name>Rajas</name> </welcome> </soap12:Body> </soap12:Envelope>"; WebClient mClient = new WebClient(); Response.Write(System.Text.Encoding.ASCII.GetString(mClient.UploadData("http://localhost:1458/forumservices/Service.asmx", "POST", System.Text.Encoding.ASCII.GetBytes(soapMessage)))); } catch (System.Net.WebException ex) { if (ex.Response != null) { Stream strm = ex.Response.GetResponseStream(); StreamReader sr = new StreamReader(strm); Response.Write(sr.ReadToEnd()); } else { Response.Write(ex.InnerException.ToString()); } } }
The compilation is fine, but i keep getting some errors as below "The remote server returned an error: (500) Internal Server Error." Please help me outJack Sparrow -------------------------------------- Defeat is not the worst of failures. Not to have tried is the true failure.
According to me to consume webservice in you application you need to add webreferace of webservice in you application than to call web service you need to create objct of that and than you can call webservice. Check on following link which give you idea about how to consume website. <a href="http://it.toolbox.com/wiki/index.php/Calling\_a\_web\_service\_from\_Asp.net">http://it.toolbox.com/wiki/index.php/Calling\_a\_web\_service\_from\_Asp.net</a>[<a href="http://it.toolbox.com/wiki/index.php/Calling\_a\_web\_service\_from\_Asp.net" target="_blank" title="New Window">^</a>]
-
I am newbie to webservices I am trying to learn about them, but got struck in the first place itself. Please help me out. My service.cs in the web service. --------------------------------
using System; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; [WebService(Namespace = "http://localhost:1458/forumservices/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class Service : System.Web.Services.WebService { public Service () { //Uncomment the following line if using designed components //InitializeComponent(); } [WebMethod] public string welcome(string name) { return "Welcome " + name; } }
now on a button click from another web pageprotected void Button1_Click(object sender, EventArgs e) { try { soapMessage = @" <?xml version=""1.0"" encoding=""utf-8""?> <soap12:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap12=""http://www.w3.org/2003/05/soap-envelope""> <soap12:Body> <welcome xmlns=""http://localhost:1458/forumservices/""> <name>Rajas</name> </welcome> </soap12:Body> </soap12:Envelope>"; WebClient mClient = new WebClient(); Response.Write(System.Text.Encoding.ASCII.GetString(mClient.UploadData("http://localhost:1458/forumservices/Service.asmx", "POST", System.Text.Encoding.ASCII.GetBytes(soapMessage)))); } catch (System.Net.WebException ex) { if (ex.Response != null) { Stream strm = ex.Response.GetResponseStream(); StreamReader sr = new StreamReader(strm); Response.Write(sr.ReadToEnd()); } else { Response.Write(ex.InnerException.ToString()); } } }
The compilation is fine, but i keep getting some errors as below "The remote server returned an error: (500) Internal Server Error." Please help me outJack Sparrow -------------------------------------- Defeat is not the worst of failures. Not to have tried is the true failure.
Your Coding looks odd to me ..! I think you are not calling the web service method..! try this link..! http://www.codeproject.com/Messages/3359929/Re-web-service.aspx[^] The Calling is Easy..!Its just like any method but little bit difference..!
LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.
-
Your Coding looks odd to me ..! I think you are not calling the web service method..! try this link..! http://www.codeproject.com/Messages/3359929/Re-web-service.aspx[^] The Calling is Easy..!Its just like any method but little bit difference..!
LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.
Sashi, When I call it using web reference it is working fine. But I have to manually call the web service using xml+soap. got any ideas
Jack Sparrow -------------------------------------- Defeat is not the worst of failures. Not to have tried is the true failure.
-
Sashi, When I call it using web reference it is working fine. But I have to manually call the web service using xml+soap. got any ideas
Jack Sparrow -------------------------------------- Defeat is not the worst of failures. Not to have tried is the true failure.