title: Visibility of a referenced class in WCF
body: <p>I will explain directly by the code : </p>
  
  <pre><code>AddObjectToDatabase()
  {
       Publish(theMessage);
  }
  </code></pre>
  
  <p>theMessage is an object of "Message" class.
  AddObjectToDatabase is a service method.
  "Publish" Method calls "CallBackMethod" of a IPublishing interface with a Message as parameter. Actually, it iterates through a <code>List&lt;IPublishing&gt;</code> static object (containing all the publishers) and for each one, call the CallBackMethod method. </p>
  
  <p>In the projet calling the service, I do that : </p>
  
  <pre><code>Class TestClass : IPublishing
  {
      ...
      TestMethod()
      {
          ...
          ISubscription subsriberProxy = ProxyCreator.createProxy(this);
          subsriberProxy.Subscribe("client1");
          theService.AddObjectToDatabase();
      }
  
      CallBackMethod(Message m)
      {
      }
  }
  </code></pre>
  
  <p>The TestClass class must implement a Method named "CallBackMethod", with receive a Message object as parameter.</p>
  
  <p>My problem here is that the service is added by "Service Reference" and the Message class is unknown by TestClass as it is not used directly in the service but into a method of the service.</p>
  
  <p>When I just add a new method to the service with Message as parameter, then the service know that object and it works perfectly.
  I can't change the architecture of the code as I have not coded this part.</p>
  
  <p>Is there a way to "know" all the object used by the service, even those who are not used directly ? </p>
  
  <p><strong>EDIT 1 :</strong><br>
  the callback is implemented via netTcpBinding.
  I can't post a section because all the config is by code.</p>
  
  <p>I tried to add <code>[KnownType(typeof(Message))]</code> in another DataContract (already known) and now I can see it in visual studio.<br>
  I also tried to change the callback method with (Object) instead of (Message), and tried this solution : <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.serviceknowntypeattribute.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.servicemodel.serviceknowntypeattribute.aspx</a></p>
  
  <p>Now the "only" issue is a InvalidCastException. Indeed he could not cast from TheServiceClass.Message to TheClassLibrary.Message<br>
  TheServiceClass is the class used with the service reference (generated), TheClassLibrary is the class where the Message class is defined.</p>