views:

149

answers:

2

Imagine I have this class

 namespace CommonLibrary
 {
     public class Report()
     {
         public DateTime Begin { get; set; }
         public int Count { get; set; }
     }
 }

This is the return type of a WCF Service method. When I use svcutil.exe it regenerates the class from metadata:

 namespace CommonLibrary
 {
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="TrafficProblemReport", Namespace="http://schemas.datacontract.org/2004/07/Indica")]
public partial class TrafficProblemReport : object, System.Runtime.Serialization.IExtensibleDataObject
{

    private System.Runtime.Serialization.ExtensionDataObject extensionDataField;

    private System.DateTime BeginField;

    private int CountField;

    [System.Runtime.Serialization.DataMemberAttribute()]
    public System.DateTime Begin
    {
        get
        {
            return this.BeginField;
        }
        set
        {
            this.BeginField = value;
        }
    }

    [System.Runtime.Serialization.DataMemberAttribute()]
    public int Count
    {
        get
        {
            return this.CountField;
        }
        set
        {
            this.CountField = value;
        }
    }
}
 }

But it conflicts with the CommonLibrary definition. I am having compilation errors when I try to pass the Webservice method result (Report) to a CommonLibrary's method:

Error 4 The best overloaded method match for 'CommonLibrary.ClassName.MethodName(CommonLibrary.Report)' has some invalid arguments

How to solve this without creating additional namespaces? (I want to avoid type conversion)

+1  A: 

Try specifying a namespace different than "CommonLibrary" when you generates the WCF service reference.

hongliang
Or add another namesspace before it. .NET guidleines often say to have a unique outer namespace, such as your company name.
Dan Diplo
but then I'll have to convert objects from one namespace to another
Jader Dias
edited the question to raise different answers
Jader Dias
+1  A: 

I could not find time yet to try it, but should not the /reference switch do the trick? I would assume that svcutil then uses the types in your assembly instead of creating new ones...

according to this I should be right: http://blogs.msdn.com/hoop/archive/2006/08/28/729242.aspx

Stefan Egli
You're my hero!
Jader Dias