I have a WCF service library project. I am trying to generate a wsdl file by launching WCF Test Client by running it in Visual studio (pushed F5). It launched WCF Test Client but it says "Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.". It also gives me the below error message.
c:\Users\xxx\AppData\Local\Temp\Test Client Projects\10.0\354421b1-b65e-45fc-8d98-ac87254a5903\Client.cs(911,26) : error CS0644: 'System.ComponentModel.PropertyChangedEventHandler' cannot derive from special class 'System.MulticastDelegate'
I added servive behavior to expose Metadata as follows. I am not sure what else I am missing here to be able to generate a wsdl file. Thanks for any help!
<services>
<service name="CU.Customer" behaviorConfiguration="Metadata">
<endpoint address="" binding="wsHttpBinding" contract="CU.ICustomer">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint name="mex" address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/CustomerService/Service1/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Metadata">
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
There is nothing wrong with your metadata bindings, but you have a compiler error in your service. This is preventing WCF from building your service class, which is needs to do to expose the metadata endpoint.
Fix this error first:
'System.ComponentModel.PropertyChangedEventHandler' cannot derive from special class 'System.MulticastDelegate'
The error (note that it's in a temp file) is happening when WCF is trying to compile the service contracts locally into classes it can use to access the service. This means that you're running into something that is legal in C#, but not legal in WCF. Most likely, given the error, you have a class that implements INotifyPropertyChanged
being used as a data contact in your operation contract.
Note that every class that gets serialized across a WCF channel is a data contract. Typically you would decorate your class with DataContract
and each field with DataMember
attributes, which directs the serializer how to handle your class. But if you don't, and you include your class as a parameter or return value in an OperationContract
, WCF just pretends like you put those attributes on every public field in your class.
In this case, my guess is you have a class, that you are passing in or out of a service call, that has:
public event PropertyChangedEventHandler PropertyChanged;
That is a public field, so unless you tell WCF otherwise, it will try to serialize it as part of the implicit data contract. But there are certain types that cannot be serialized this way, and MulticastDelegate
is one of them.
To fix, and in the future avoid, this problem, always decorate the types you use for services with DataContract
and DataMember
explicitly. It's perfectly safe to put those attributes on any class -- if you never try to serialize it, the attributes are simply ignored.