WSE: Not-So-Minor Details
First let's take a look at a simple webservice that I setup in my sample project.
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[Policy("MyPolicy")]
public class Service : System.Web.Services.WebService
{
public Service()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
#region Basic
[WebMethod]
public string HelloWorld()
{
return "Hello, World";
}
#endregion
#region WSE
[WebMethod]
public string HelloWSE()
{
SecurityToken token = RequestSoapContext.Current.IdentityToken;
if (token != null)
{
string Name = token.Identity.Name;
return String.Format("Hello, {0}", Name);
}
return null;
}
#endregion
}
If you go simply add a new webservice to your web project, it will give you the skeleton with all of the absolutely necessary attributes - almost all of them, anyways - in the right places. We just need to add the PolicyAttribute located in the Microsoft.Web.Services3 namespace to the webservice class. We are looking for the attribute that takes the string arguement. What do we put here? Do you remember the name of the policy you entered here? Pass that name - type-friendly, of course - to the PolicyAttribute.
Next, open up you web.config file in the web project. If you followed my directions, you should see something that looks like the following:
<securitytokenmanager>
<add type="WebService.TokenManager, Microsoft.Web.Services3, Version=3.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
namespace="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-
secext-1.0.xsd" localName="UsernameToken" />
</securitytokenmanager>
We need to make this look like this:
<securitytokenmanager>
<add localName="UsernameToken" type="WebService.TokenManager"
namespace="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-
secext-1.0.xsd"/>
</securitytokenmanager>
The localname attribute is the type-friendly name of the token that will be passed to our token manager and the type attribute is the namespace and class of my token manager.
That is the end of the tweaking phase, next we'll setup the client to consume the service using WSE.






0 Comments:
Post a Comment
<< Home