Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How To Authenticate Your Web service??

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Define a web service in .net?

1015


Types of instancing properties and explain each. Tell the difference between multiuse,singleuse and globalmultiuse and which is default ?

2726


What is the concept of view state in asp.net?

975


What is Web Server Control Templates.?

1012


Name the two properties are on every validation control?

938


Explain about ASP.NET?

1030


Explain the updatepanel?

952


Why Unload event of MasterPage Calls first in ASP.net ?

993


What is active web pages?

912


Why do we need asp.net?

980


What does asp stand for in asp.net?

936


Differentiate between Server.Transfer and Response.Redirect with functionality? Why we can choose one over the other?

1118


What is cache in asp net?

960


What are validator? Name the validation controls in asp.net?

962


What are the new features added from ASP to ASP.NET?

1031