tags:

views:

28

answers:

1

I am creating a service reference to a WCF service using VS2008 but the generated reference file has 2 classes defined representing the same object. Any ideas why this would be? See result below - THView and THView1 were generated while I'm expecting only THView.

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="THView", Namespace="http://schemas.datacontract.org/2004/07/CH.BusinessServices.Model")]
[System.SerializableAttribute()]
public partial class THView : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="THView", Namespace="http://tempuri.org/")]
[System.SerializableAttribute()]
public partial class THView1 : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {
+2  A: 

Service files are generated based on the service's metadata (WSDL), and this particular service's metadata apparantly defines two different THView types.

They may look similar (they have the same name), but they are actually different because they live in two different namespaces (notice the Namespace property of the DataContractAttribute), respectively

  • http://schemas.datacontract.org/2004/07/CH.BusinessServices.Model
  • http://tempuri.org/

Because the namespaces are different, the types are considered different. That's simply how XML works.

It looks as though the developer who defined the original service forgot to change the default XML namespace on one or more of the types exposed by the service - at least, http://tempuri.org/ is the default namespace in WCF.

It's strongly recommended that the default namespace is changed to a namespace 'owned' by the service owner.

Mark Seemann