calling web service
-
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 page
protected 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 out I had posted the exam same thing in ASP.NET forum, but got no replies.
Jack 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 page
protected 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 out I had posted the exam same thing in ASP.NET forum, but got no replies.
Jack 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. http://it.toolbox.com/wiki/index.php/Calling_a_web_service_from_Asp.net[^]