WCF Service Reference - Proxy not generated when reusing types
I have two companion C # (.NET v4.0) projects, an ASP.NET website and a "self-contained" WCF Console application. The site code calls the WCF service for different things; both were written a couple of years ago and work great.
Both the console application and the website share a common class library between them (named MyLibrary
in this example); this is added as a link to both projects.
The console application is pretty simple - for example, I have IService.cs
:
[ServiceContract]
public interface IService
{
[OperationContract]
List<MyLibrary.MyClass> DoSomething(int ID);
}
and then Service.cs
:
public class Service : IService
{
public List<MyLibrary.MyClass> DoSomething(int ID)
{
// etc
return result;
}
}
... and it all works. However, today I need to add something trivial to both sides - one more parameter needs to be added for one of the methods. I updated my WCF application, built it, started it and then went to the site and tried to "Update Service Link".
At this point, the site crashed: generating a service link no longer creates a proxy. However, if I deselected the "Reuse all links" option, the proxy is created: this breaks my code a lot, although I need to split the links to MyLibrary
through the whole code.
After some digging, I tried to create a link using svcutil
:
svcutil /t:code http://localhost/MyService /r MyLibrary.dll
which throws an error:
Attempting to download metadata from 'http://localhost/MyService' using WS-Metadata Exchange or DISCO. Error: Cannot import wsdl:portType Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: Referenced type 'MyLibrary.MyClass, MyLibrary, Version=2.0.53
33.26816, Culture=neutral, PublicKeyToken=null' with data contract name 'MyLibrary.MyClass' in namespace 'http://schemas.datacontract.org/2004/07/MyService' cannot be used since it does not match imported DataContract. Need to exclude this type from referenced types.
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='IService']
I cannot understand what happened; I have seen other posts about this error, but they all say that the referenced class is the same - the WCF application uses the same code in the MyLibrary
way I call from svcutil
above; both will compile at the same time. Also, I don't do anything differently that I haven't done dozens of times before.
Can anyone suggest where to start troubleshooting this issue? Sorry in advance if I was looking for any syntax in my code examples during obfuscation :)
source to share
I stumbled upon the answer by accident: if I uncheck the "Always generate messages" option and then "Refresh the service link" everything goes back to normal.
I'm sure I really should be using DataContract (as mentioned in the comments on my OP), but I'll take a quick win and hide my ignorance for another day!
source to share