Page view counter
Adding user name and password to SOAP message header Subscribe to this thread
Last post 01-05-2009 9:52 AM by kobruleht. 9 replies.
Sort Posts:
01-01-2009 3:56 PM
Adding user name and password to SOAP message header

SL appl asks for user name and password. How to pass user name and password to SOAP WebService for custom validation?

I tried code below but got error on line

proxy.Headers.Add(header);

about missing Headers propery.

Andrus.

 

var proxy = new DocumentServiceReference.DocumentSoapClient();

MessageHeader header = MessageHeader.CreateHeader(typeof(UserCredentials).Name,

UserCredentials.WS_NAMESPACE,new UserCredentials("user", "password"), false);

proxy.Headers.Add(header);

proxy.SaveAssetDocumentCompleted += proxy_AddOrderCompleted;

proxy.SaveAssetDocumentAsync();

 

class UserCredentials

{

public const string WS_NAMESPACE = "urn:LOBApplicationFramework.Security";

public string UserName { get; set; }

public string Password { get; set; }

public UserCredentials()

{

}

public UserCredentials(string userName, string password)

{

UserName = userName;

Password = password;

}

}

 

kobruleht

Loading...
Joined on 04-30-2008
Posts 293
01-01-2009 4:45 PM
Re: Adding user name and password to SOAP message header

Hi,

check out this article:

http://www.silverlightshow.net/items/Building-a-Silverlight-Line-Of-Business-Application-Part-3.aspx

Thanks, Davide

Blog Twitter Silverlight Experts

Please "Mark as Answer" if this answered your question.

davidezordan

Loading...
Joined on 05-23-2008
Italy
Posts 727
01-01-2009 5:57 PM
Re: Adding user name and password to SOAP message header

Thank you. I tried this code with SOAP Web Service.

In service line 

MessageHeaders messageHeaders = OperationContext.Current.IncomingMessageHeaders;

Causes NullReferenceException

Any idea how to make this code to work with SOAP web service ?

Andrus.

kobruleht

Loading...
Joined on 04-30-2008
Posts 293
01-01-2009 7:04 PM
Re: Re: Adding user name and password to SOAP message header

The source code of the article works fine for me.

However you can find here a simpler example using custom SOAP headers:

http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=silverlightws&DownloadId=3473

Thanks, Davide

Blog Twitter Silverlight Experts

Please "Mark as Answer" if this answered your question.

davidezordan

Loading...
Joined on 05-23-2008
Italy
Posts 727
01-02-2009 5:15 AM
Re: Re: Adding user name and password to SOAP message header

Thank you. 

Have you tried with ASMX Web service?

I'm looking for a way to get message headers from ASMX web service, not from WCF web service.

Code sample you posted uses WCF web service.

Andrus.

kobruleht

Loading...
Joined on 04-30-2008
Posts 293
01-02-2009 8:27 AM
Re: Re: Re: Adding user name and password to SOAP message header

Hi Andrus,

I suggest you to use WCF services instead of "old" asmx, they are more scalable.

Once you have upgraded to WCF, use the last example I've posted, it works very well.

Thanks, Davide

Blog Twitter Silverlight Experts

Please "Mark as Answer" if this answered your question.

davidezordan

Loading...
Joined on 05-23-2008
Italy
Posts 727
01-02-2009 1:53 PM
Re: Re: Re: Adding user name and password to SOAP message header

I'm planning to host web service in MONO. I have'nt found a way to run .svc service from MONO so I'm forced to use asmx which works OK.

I found the following article about retrieving SOAP headers in ASMX web service

http://www.codeproject.com/KB/cpp/authforwebservices.aspx

Should I use this method ?

Andrus.

kobruleht

Loading...
Joined on 04-30-2008
Posts 293
01-02-2009 7:28 PM
Marked as Answer
Re: Re: Re: Re: Adding user name and password to SOAP message header

Check out this thread:

http://silverlight.net/forums/p/62643/155224.aspx

Thanks, Davide

Blog Twitter Silverlight Experts

Please "Mark as Answer" if this answered your question.

davidezordan

Loading...
Joined on 05-23-2008
Italy
Posts 727
01-05-2009 8:26 AM
Re: Re: Re: Re: Adding user name and password to SOAP message header

So it seems like the best way to deal with this is to have a centralized method for calling web services.  Is that correct?

ljun

Loading...
Joined on 12-08-2008
Posts 6
01-05-2009 9:52 AM
Re: Re: Re: Re: Adding user name and password to SOAP message header

My goal is to exchange the following info with ASMX service:

1. SQL Server login credentials (user name, password, database etc) 

2. ValidationException and other exception message texts.

I think that best way is not use message headers at all.

So I created special type

class MessageHeader {

public string User, Class, ExceptionText;

...

}

and pass this as  ref parameter to every web method call

List<Customer> GetCustomers( ref header, ... )

Ugly, but seems to be only solution.

Andrus.

kobruleht

Loading...
Joined on 04-30-2008
Posts 293
Microsoft Communities