Switch from WCF-BasicHttp to WCF-WSHttp in BizTalk?
I learned a new trick that I know someone out there will appreciate…
First, here’s a little background. Some time ago, when I hosted my first BizTalk service with WCF, I ran the BizTalk WCF Service Publishing Wizard and was prompted for an adapter name. I chose WCF-BasicHttp, assuming that I could easily change this later (as most of you out there, it’s nice to start with no security, get things working, and then progress to enable more complicated security schemes).
And for those that I haven’t done this before: After finishing the wizard, the next steps involve verifying/fixed the IIS app pool settings and enabling the receive location. After that, you should be able to browse the service. Something like this should appear:
If you click on the link to browse the WSDL, you’d find that there is no advanced policy configuration.
Great, we’ve got our basic http service up. At some point, you might want something a little more secure, and this was my initial frustration. I opened up the BizTalk Admin Console, found the receive location hosting the service, and switched from WCF-BasicHttp to WCF-WSHttp. As part of this, in my case, I added the URI, specified a Security mode of Transport, and a Transport client credential type of Basic.
I accepted the changes, made sure the receive location was enabled, and tried browsing my service again.
But, as you can see, it didn’t work. At the time, not knowing how to fix this, I re-ran the wizard, chose WSHttp, etc. That made the WSHttp service browsable, but I was frustrated that I had to re-run the wizard, and I happened to have chosen a slightly different naming for the operation, which caused additional headache and rework, etc.
That’s why I’m writing this post. There’s a better way. Let’s go back in time… instead of re-running the wizard and choosing the WSHttp adapter (or Custom-Isolated), I could have simply changed the .svc file, i.e. C:\Inetpub\wwwroot\HelloWorldService\HelloWorld.svc. The file originally had this inside it:
<%@ ServiceHost Language=”c#” Factory=”Microsoft.BizTalk.Adapter.Wcf.Runtime.BasicHttpWebServiceHostFactory, Microsoft.BizTalk.Adapter.Wcf.Runtime, Version=188.8.131.52, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ %>
I changed the HelloWorld.svc ever so slightly to read:
<%@ ServiceHost Language=”c#” Factory=”Microsoft.BizTalk.Adapter.Wcf.Runtime.WSHttpWebServiceHostFactory, Microsoft.BizTalk.Adapter.Wcf.Runtime, Version=184.108.40.206, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ %>
I saved the file, and… (drum roll please)
It works! Here I’m showing the WSHttp WSDL. You’ll notice that you see the corresponding policy information in the file.
So, in conclusion, yes you can start with one WCF adapter type and switch it later by 1) updating the receive location in the Admin Console, and 2) updating the .svc file. For reference here are factory values for the .svc file that the wizard allows you to pick from: