0

I'm helping someone use Visual Studio Tools For Applications to connect an Infopath application to a service written using WCF that requires a username and password be sent in the SOAP header (clientCredentialType="UserName"). The service is using basicHttpBinding.

Infopath 2010 relies on Visual Studio Tools For Applications 2005 and so I am stuck having to add a "Web Reference" instead of a "Service Reference". I have never had to do this before and it is becoming very problematic trying to figure out how to do it.

In a Service Reference I just say:

service.Credentials.UserName.UserName = "username";
service.Credentials.UserName.Password = "password";

But when consuming using a Web Reference the Credentials property behaves differently and I can't get it to pass the username and password in the SOAP header automatically.

I have tried a few things including these with no luck:

MyService service = new MyService();
CredentialCache cache = new CredentialCache();
// I've tried "Basic" and string.Empty as well in the place of "UserName"
cache.Add(new Uri(service.Url), "UserName", new NetworkCredential("username", "password"));
service.Credentials = cache;
service.PreAuthenticate = true;

service.MyMethod();

and

MyService service = new MyService();

service.Credentials = new NetworkCredential("username", "password");

service.MyMethod();

but have had no luck at all. Logging the entire message on the service, the username and password are not included in the SOAP header at all and I receive the following error: "An error occurred when verifying security for the message."

John Saunders
  • 160,644
  • 26
  • 247
  • 397
omatase
  • 1,551
  • 1
  • 18
  • 42
  • Hi, any luck on this? I need something similar. In my case, I am looking for a way to a java application pass user/password in the soap header to be validated by a wcf service. Thanks! – Roberto Oct 16 '12 at 13:48
  • The answer really is just that you can't do it automatically from .Net 2.0. In the case of Java, however, the answer may be entirely different. I have gone the lazy route in an Android app (which of course was Java) by just constructing the SOAP manually and posting to the server. – omatase Feb 11 '13 at 16:20

2 Answers2

1

The answer really is just that you can't do it automatically from .Net 2.0.

omatase
  • 1,551
  • 1
  • 18
  • 42
0

There are reasons why WCF has replaced ASMX. Support for security standards is one of them.

If you're using VSTA, then I presume that you can use COM objects. You could create a COM object using .NET 3.5 (which is just .NET 2.0 SP2 plus some extra libraries). This COM object could use a WCF Service Reference to consume the service, yet would expose only COM. Any code that can consume a COM object would be able to consume your "proxy object".

John Saunders
  • 160,644
  • 26
  • 247
  • 397