C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » Webservices »

Secure webservice


Posted Date: 13 Oct 2009      Posted By: Saroj Kumar Raut      Member Level: Silver     Points: 1   Responses: 2



1. Can anybody tell me that how to secure a webservice with example ??
2. How to call a webservice dynamically ??

Thanks in advance.





Responses

Author: seema    13 Oct 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

how to secure a webservice with example ??:
http://msdn.microsoft.com/en-us/library/aa302428.aspx



Author: seema    13 Oct 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

How to call a webservice dynamically ??






Step 1.

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class CustomerWebService : System.Web.Services.WebService
{
[WebMethod]
public string Register(long id, string data1)
{
return "ID.CUSTOMER";
}
}

Step 2.

POST /WebServices/CustomerWebService.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/Register"

<?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>
<Register xmlns="http://tempuri.org/">
<id>long</id>
<data1>string</data1>
</Register>
</soap:Body>
</soap:Envelope>

Step 3. Create HttpWebRequest passing the WS url and soap action (similar to method name) and execute the request.

string soap =
@"<?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>
<Register xmlns=""http://tempuri.org/"">
<id>123</id>
<data1>string</data1>
</Register>
</soap:Body>
</soap:Envelope>";

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://localhost/WebServices/CustomerWebService.asmx");
req.Headers.Add("SOAPAction", "\"http://tempuri.org/Register\"");
req.ContentType = "text/xml;charset=\"utf-8\"";
req.Accept = "text/xml";
req.Method = "POST";

using (Stream stm = req.GetRequestStream())
{
using (StreamWriter stmw = new StreamWriter(stm))
{
stmw.Write(soap);
}
}

WebResponse response = req.GetResponse();

Stream responseStream = response.GetResponseStream();
// TODO: Do whatever you need with the response



Post Reply
You must Sign In to post a response.
Next : Pdf files for webservice
Previous : How to send to sms to mobiles by using webservice
Return to Discussion Forum
Post New Message
Category: Webservices

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use