How To Authenticate Your Web service??



How To Authenticate Your Web service??..

Answer / maloy.adhikari

My web service looks like this::

[WebService(Namespace = "maloy.adhikari@in.com",Name="My Web
Services",Description="For My Experiments")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[WebServiceBinding(Name = "TestService", ConformsTo =
WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using
ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]

public class Authnticate : System.Web.Services.WebService
{
public Authnticate ()
{
}
public UserCredentials consumer;
[WebMethod]
[SoapDocumentMethod(Binding = "TestService")]
[SoapHeader("consumer",Required = true)]

public string GetMethod()
{
if(CheckUser())
return consumer.UserID+ "You Are Authenticate";
else
return "Please Provide Your Proper Credential";
}

private bool CheckUser()
{
if (consumer != null)
{
if (consumer.UserID== "maloy" && consumer.password ==
"adhikari")
return true;
else
return false;
}
else
return false;
}

}

public class UserCredentials :
System.Web.Services.Protocols.SoapHeader
{
public string UserID;
public string password;
}
-----------
In the service I have created one method.There i check
ID,Password.Also i have created one class that inherited
from soapheader class.There i define that ID,Password.
-----------
Now go to your application.click addreference then add the
proper webservice by original url that you have created.
-----------
Authenticate.TestService service = new
Authenticate.TestService();

Authenticate.UserCredentials user = new
Authenticate.UserCredentials();

string ID=ConfigurationSettings.AppSettings["ID"].ToString();
user.UserID= ID
string
Password=ConfigurationSettings.AppSettings["password"].ToString();

user.Password= Password

service.UserCredentialsValue = user;
Response.Write(service.GetMethod());
-----------
In my application i have just created instance of
Webservice(mine is Authenticate) & instance of
UserCredentials class that is inherited from soapheader.
-----------
O/P--
1. If you provide proper ID,Password in AppSetting Tehn out
put will be:::maloy you Are Authenticate.
2. If you provide other userID & password output will be::
Please Provide Your Proper Credential

Is This Answer Correct ?    3 Yes 1 No

Post New Answer

More ASP.NET Interview Questions

Explain server side state management system.

0 Answers  


How to send data through querystring to another page but it should not be displayed in URL

2 Answers   EMR, Powersoft19,


To call a Web service SOAP which transport protocol you use?

3 Answers   Siebel,


Explain the difference between page.registerclientscriptblock and page.registerstartupscript?

0 Answers  


difference between gridview,data list and repeater control

7 Answers   ABC, Olive Tech,






Explain diff. Betn dataset and recordset?

0 Answers  


while developing webservices if i want some users to use my webservice only how can i give security to my webservice?

0 Answers  


what is diffrence between debug class and trace class in asp.net ?

2 Answers  


what is the Difference between Dim Object as object AND dim obj as myform?

1 Answers   Microsoft,


What are three ways that you can use a compare validator?

1 Answers  


How do I send e-mail from an ASP.NET application ?

1 Answers  


What is a page life cycle?

0 Answers  


Categories