Question

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."

Was it helpful?

Solution

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

OTHER TIPS

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".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top