TechBubbles Microsoft Technology BLOG

Adding Security Credentials to SOAP

The WSE 3.0 for .NET enables the developers for creating one or more security credentials that can be added to the SOAP Message.

The following procedure describes how to add one or more security credentials to a SOAP Message.A computer must be configured to accept the SOAP Messages embedded with the security credentials.

Two types of security credentials that can be setup for the computer

  1. X.509 certificate.
  2. Username and Password.

You can configure the computer for X.509 certificate by reading the  SOAP Messages signed by an X.509 Certificate.

You can also configure the computer for Username Token by validating SOAP Messages signed by Username Token.

Following procedure is To Add a security token to SOAP

1.  Open the Web Service Client project

2.Add references to the Microsoft.Web.Services3 and System.Web.Services assemblies. 

3. Add a Web Reference to the Web service that is to receive the SOAP message signed with the UsernameToken.

4. Add the folllowing user directives

using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography.X509Certificates;

using Microsoft.Web.Services3;
using Microsoft.Web.Services3.Design;
using Microsoft.Web.Services3.Security;
using Microsoft.Web.Services3.Security.Tokens;

 5. Write the following code by overriding the SecureMessage Method  in web  service.

public override void SecureMessage(SoapEnvelope envelope, Security security)
{
UsernameToken userToken;
userToken = new UsernameToken(userName, userPasswordEquivalent,
    PasswordOption.SendNone);
// Adds the token to the SOAP header.
security.Tokens.Add(userToken);
}

About the author

Kalyan Bandarupalli

My name is kalyan, I am a software architect and builds the applications using Microsoft .NET technologies. Here I am trying to share what I feel and what I think with whoever comes along wandering to Internet home of mine.I hope that this page and its contents will speak for me and that is the reason I am not going to say anything specially about my self here.

3 Comments

  • Hi, is this compatible to .net 3.5? Because I’m trying to consume a java webservice that requires UsernameToken. I’m using asp.net 3.5 as a client.
    I can’t find a good solution on the net on how to attach the soapheader with UsernameToken on every web method request.

    I hope you can help. Thanks in advance

TechBubbles Microsoft Technology BLOG

Follow me

Archives

Tag Cloud