I hate to admit it, but I spent a few hours pulling my hair out on this one. I created a new WCF Service and added a few services. I then added a service reference to some small consuming applications and everything worked fine. I then added a service reference to a large website which has about ~50 referenced assemblies. This time when I did it, my web.config serviceModel section wasn’t updated by Visual Studio 2010. Normally, Studio will generate bindings and client end points for you. What the hell! I was baffled.
I soon discovered that the website wouldn’t compile with this WCF service reference either, which was odd because I obviously hadn’t written any consuming code for it yet. The compiler error was this:
Parser Error Message: Reference.svcmap: Failed to generate code for the service reference XXXXOrderService’.
Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension:
Error: Could not load file or assembly …
As it turns out, the problem was happening because Reuse types in all referenced assemblies was enabled in the service reference settings, which is is enabled by default. Well, that wasn’t WHY the error was occurring and I haven’t taken the time to become well versed enough in this matter (behind on a deadline), but this can apparently cause issues if both the consuming application and the WCF service reference the same assemblies. I didn’t actually spend the time figuring out which assembly was causing the problem, but that wouldn’t matter to you anyway. I simply unchecked Reuse types for now and everything started working; I deleted the service reference, re-added it, and the web.config was properly updated with the client endpoints and service bindings. Badda Boom. Service Model happiness.
If you don’t know how to get to this, you can either click the advanced button when adding the service reference or configure after it’s been added by clicking Configure Service Reference on the svcmap.
I hope this helps someone.