This is a really old note that I wrote long before I decided to create a blog on Grignola.ch. I was very lucky to see a Brian H. Prince’s session at DevReach 2012 about soft skills (Soft Skillz : They aren’t just for humans anymore) and one thing that really caught my attention was this sentence: “Every time that you learn something write an article about it”.
Let’s say that you need to fix something, after hard work you finally resolve it and you just move to the next problem on the list. But what happens after 6 months when you have to work on the same area? I’m almost sure that you have to restart everything from scratch because you didn’t have time to take notes (or maybe you took notes but you can’t understand them anymore). This is exactly why I couldn’t agree more with Prince: if you take your time to write an article so that it’s useful to everybody it’ll be useful also to you after 6 months. Let’s get back on topic and solve a very annoying problem with WCF when you are trying to use Sudz-C (http://sudzc.com) to generate an iOS client. The problem that you face is that WCF generates a modular WSDL (a WSDL that imports other WSDL’s or XSD’s) that even if it’s standard it doesn’t work with Sudz-C. Thanks to this great MSDN article you can solve everything in a couple of minutes: http://blogs.msdn.com/b/dotnetinterop/archive/2008/09/23/flatten-your-wsdl-with-this-custom-servicehost-for-wcf.aspx
Simply add the 2 classes to your project and configure the ServiceHost to use the FlatWsdlServiceHost. If you configure the ServiceHost in the code behind like I do you can just skip the last part of the linked article:
<%@ ServiceHost Language="C#" Factory="Thinktecture.ServiceModel.FlatWsdlServiceHostFactory" Service="Ionic.Samples.Webservices.MyWebService"%>
and initialize the ServiceHost with the following snippet:
var serviceHost = new FlatWsdlServiceHost(typeof(MyWebService), new Uri("http://localhost:85")); serviceHost.AddServiceEndpoint(typeof(IMyWebService), new BasicHttpBinding(BasicHttpSecurityMode.None), "myAddress"); serviceHost.Behaviors.Add(new FlatWsdl());
Now you download the flat WSDL file from your WCF Web Service and upload it to Sudz-C. Remember to expose the WSDL with the ServiceMetadataBehavior otherwise “http://localhost:85/?wsdl” doesn’t work!
var metad = serviceHost.Description.Behaviors.Find<ServiceMetadataBehavior>(); if (metad == null) metad = new ServiceMetadataBehavior(); metad.HttpGetEnabled = true; serviceHost.Description.Behaviors.Add(metad);