Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

web service security header help...

Status
Not open for further replies.

d2007

Programmer
May 17, 2007
18
0
0
US
Using VB. VS 2005.

I have added a web reference to my project for a web service using the specified http WSDL.

I have added an instance of the service to my page:

Example: Dim ws As New myservice

One of the requirements is that I use header authentication in the SOAP response (username and password). What is the best way to approach this?

Is it as simple as the following:

Imports Microsoft.Web.Services3
Imports Microsoft.Web.Services3.Security
Imports Microsoft.Web.Services3.Security.Tokens

Dim ws As New myservice

Dim userToken As New UsernameToken("username", "pass")
ws.SetClientCredential(userToken)

New to web services like this, is there an easy way to preview the SOAP that is generated?

Thanks very much in advance for any suggestions.
 
Do you mean you want to require that users send credentials via a SOAP header while making a request to a web service?

This is how that would look:

Code:
//define a header class
public class AuthHeader : SoapHeader
{
    public string Username;
    public string Password;
}

//in web service class
public AuthHeader Authentication;

[SoapHeader ("Authentication", Required=true)]
[WebMethod (Description="Returns a string")]
public string GetString()
{
     string user = Authentication.Username;
     string pass = Authentication.Password;

     //check whatever you want with the user name and password

     //return data
}

As far as examining the SOAP, you can disect the request with a tool like Fiddler.


MCP, MCTS - .NET Framework 2.0 Web Applications
 
Thanks for the reply -- I will check out that tool.

I am actually consuming a web service that requires a SOAP header and that is what I am trying to create.
 
Oh. That code, in relation to the above, would look like:

Code:
ServiceProxy.MyService service = new ServiceProxy.MyService();
ServiceProxy.AuthHeader header = new ServiceProxy.AuthHeader();

header.Username = "...";
header.Password = "...";
service.AuthHeader = header;

service.GetString();

If you're using "basic authentication" that's different.

MCP, MCTS - .NET Framework 2.0 Web Applications
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top