2

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>
Jyina
  • 2,530
  • 9
  • 42
  • 80

1 Answers1

2

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.

Michael Edenfield
  • 28,070
  • 4
  • 86
  • 117
  • I noticed that my service does not have any data contracts/data members defined. I have only one Operation contract available in the service. Any ideas on where else I should look into? On another note, the service builds and hosts successfully. But the problem is that it fails to launch WCF Test Client. Thank you! – Jyina Jun 05 '12 at 13:27
  • Yeah, lemme expand my answer. – Michael Edenfield Jun 05 '12 at 15:13
  • Thank you very much. It makes perfect sense now. I see that the class that was passed as a parameter to the operation contract is implementing System.ComponentModel.INotifyPropertyChanged. – Jyina Jun 05 '12 at 15:35