title: Passing object type to WCF Service Application in VS 2010
body: <p>I need to pass several different varieties of user defined types as parameters to the same method in a WCF Service Application i.e. CompositeType, CompositeType2, CompositeType3, etc. </p>
  
  <p>Here's the steps to reproduce:</p>
  
  <p>Step 1. Launch Visual Studio 2010.</p>
  
  <p>Step 2. Create a new "WCF Service Application" project.</p>
  
  <p>Step 3. Build and run the project (Debug->Start Debugging from main menu or right click on project in Solution Explorer and click Debug->Start New Instance).</p>
  
  <pre><code>    Results: A Web Browser will display the contents of the web folder.
  </code></pre>
  
  <p>Step 4. Add the following to the IService1.cs interface:</p>
  
  <pre><code>[OperationContract]
  string GetDataAsObject(object value);
  [OperationContract]
  CompositeType GetDataUsingDataContractAsObject(object composite);
  </code></pre>
  
  <p>Step 5. Add the following to the Service1.svc.cs service:</p>
  
  <pre><code>public string GetDataAsObject(object value)
  {
      int tmpInt = -1;
      tmpInt = (int)value;
      return string.Format("GetDataAsObject Responded You entered: {0}", tmpInt);
  }
  
  public CompositeType GetDataUsingDataContractAsObject(object composite)
  {
      CompositeType tmpCompositeType;
      tmpCompositeType = (CompositeType)composite;
      if (tmpCompositeType == null)
      {
          throw new ArgumentNullException("composite");
      }
      if (tmpCompositeType.BoolValue)
      {
          tmpCompositeType.StringValue += "Suffix";
      }
      return tmpCompositeType;
  }
  </code></pre>
  
  <p>Step 3. Add a new "Windows Forms Application" project to the solution.</p>
  
  <p>Step 4. Right click on References in the Solution Explorer and Select "Add Service Reference" then click the Discover button then click OK.</p>
  
  <pre><code>    Results: A Service Reference named ServiceReference1 is added to the project.
  </code></pre>
  
  <p>Step 5. Add a button to the form and in the click event add: </p>
  
  <pre><code>string tmpStr = string.Empty;
  ServiceReference1.Service1Client tstServiceClient;
  tstServiceClient = new ServiceReference1.Service1Client();
  tmpStr = tstServiceClient.GetData(1);
  tmpStr = tstServiceClient.GetDataAsObject(1);
  tmpCompositeType = new ServiceReference1.CompositeType();
  tmpCompositeType.BoolValue = true;
  tmpCompositeType.StringValue = "Hello";
  tmpStr = tstServiceClient.GetDataUsingDataContract(tmpCompositeType);
  tmpStr = tstServiceClient.GetDataUsingDataContractAsObject(tmpCompositeType);
  </code></pre>
  
  <p>Step 6. Place a break point at tmpStr = tstServiceClient.GetData(1); then Run the forms app and click the button then step over the code.</p>
  
  <pre><code>Results: An exception occurs at
  tstServiceClient.GetDataUsingDataContractAsObject(tmpCompositeType)
  
  The exception while trying to deserialize the message: 
  
  There was an error while trying to deserialize parameter composite.
  The InnerException message was 'Error in line 1 position 302.
  Element 'http://tempuri.org/:composite' contains data from a type that maps to the name 'CompositeType'.
  The deserializer has no knowledge of any type that maps to this name.
  Consider using a DataContractResolver or add the type corresponding
  to 'CompositeType' to the list of known types - for example,
  by using the KnownTypeAttribute attribute or by adding it to the list
  of known types passed to DataContractSerializer.'.
  Please see InnerException for more details.
  </code></pre>
  
  <p>Adding the KnownTypeAttribute didn't work.
  I want the minimum complexity required to make it work i.e. I don't want to replace the deserializer that is being used...I just want to fix this error,
      "The deserializer has no knowledge of any type that maps to this name"
  so that it knows what a CompositeType is.  Is there something that I need to add to the CompositeType class?  Is there anyway to let the deserializer know about the CompositeType type?</p>