Jader Dias
Jader Dias

Reputation: 90535

How to avoid conflicts when using services? (.NET C#)

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)

Upvotes: 0

Views: 1309

Answers (2)

Stefan Egli
Stefan Egli

Reputation: 17028

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

Upvotes: 1

hongliang
hongliang

Reputation: 625

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

Upvotes: 2

Related Questions