Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding a service reference create duplicated definitions for enums and methods

I'm adding Navision Web Services to a simple Windows Forms Application using Add Service Reference functionality inside Visual Studio 2010, the reference are generated but inside the code there are duplicated definitions that stop the code from compiling, for example:

Error

The namespace 'WindowsFormsApplication1.ServiceReference1' already contains a definition for 'Status' C:\Trash\WindowsFormsApplication1\WindowsFormsApplication1\Service References\ServiceReference1\Reference.cs

and inside Reference.cs I have

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.1015")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:microsoft-dynamics-schemas/page/salesheaderpage")]
public enum Status {

    /// <remarks/>
    Open,

    /// <remarks/>
    Released,

    /// <remarks/>
    Pending_Approval,

    /// <remarks/>
    Pending_Prepayment,
}

and

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="Status", Namespace="urn:microsoft-dynamics-schemas/page/salesheaderpage")]
public enum Status : int {

    [System.Runtime.Serialization.EnumMemberAttribute()]
    Open = 0,

    [System.Runtime.Serialization.EnumMemberAttribute()]
    Released = 1,

    [System.Runtime.Serialization.EnumMemberAttribute()]
    Pending_Approval = 2,

    [System.Runtime.Serialization.EnumMemberAttribute()]
    Pending_Prepayment = 3,
}

I already tried to uncheck Reuse types in referenced assemblies but the duplicated definitions are still generated in both cases.

any ideas?

EDIT: the Page is a custom Page connected to the standard table 36 (Sales Header)

like image 763
Guido Preite Avatar asked Nov 20 '13 09:11

Guido Preite


1 Answers

The issue seems to be that the serialization is happening twice:

//Xml Serializer
[System.Xml.Serialization.XmlTypeAttribute(...

//DataContract Serializer
[System.Runtime.Serialization.DataContractAttribute(...

Assuming there are no server-side issues:

  • The first thing to check is that you don't have any enums locally with the same name since it often breaks types re-usage.

  • Also, using Add Web Reference should provide working code.

  • If the other points didn't fix the issue (or they aren't useful to you even if they produce working code), I'd next try using svcutil to manually build a proxy class through a specific serializer. Since Dynamics services should be XML ones, I'd go with /serializer:XmlSerializer (EDIT: I mistyped the command line parameter!)

The command might look like:

svcutil <ServiceURL> /Language:CS /target:Code 
/out:MyServiceProxy.cs /config:MyServiceProxy.config /serializer:XmlSerializer

Default location of the tool should be %ProgramFiles%\Microsoft SDKs\Windows\v6.0\Bin according to MSDN Reference for the tool (Framework ver 4.0)

like image 75
Alex Avatar answered Sep 20 '22 14:09

Alex