Tuesday, August 19, 2008

Chucking Rocks at the Moon with WCF and NTLM Errors

So, I've been reading, studying, and toying mentally with WCF, but it was now time for me to do something with WCF.

So I created my "hello world" WCF service, and straight off the get go...problem.

I created my WCF web service (in an existing web app, going that route), left everything as default, and got the service running in debug mode. I copied default URL (with the ?wsdl) that comes up when you run the web service.

I then created a new web project, right clicked in VS 2008 on the Add Web Service, and pasted in the URL from above. The discovery took place, and everything looked good.

So in the code behind page_load method on my default page, I do something like this. Not your names will very.

ServiceReference1.WCFTestClient x =
new Consumer.ServiceReference1.WCFTestClient ();
try
{
Response.Write ( x.GetData ( 3 ) );
x.Close ();
}
catch ( System.Exception ex )
{
Response.Write ( ex.ToString () );
}


then I fire it up...bomb. Something about an NTLM anonymous blah blah blah error.

I read, figure out you can turn NTLM off (if you are using Cassini, right click on your web application sln, properties, start up, uncheck NTLM). But that wasn't going to work as the web app that I'm adding the web service into actually needs NTLM.

So, I played around. By default, the binding used is wsHttpbinding. You can change that to get things running. In the web config on the web app that host the service, I changed the binding entry from wshttpbinding to basicHttpBinding. On my consumer web app, I updated the web service reference, then went into the web config and changed the security mode setting lines in the basicHttpBinding.

<security mode="TransportCredentialOnly">
<
transport clientCredentialType="Ntlm" proxyCredentialType="None"
realm="" />
<
message clientCredentialType="UserName" algorithmSuite="Default" />
</
security>


Well, once I fired up again in debug, everyting works, and allegidly NTLM is still in place. Hope this helps someone. Not sure how secure all this is, so I will keep playing.

No comments: