14

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)

7
  • 1
    Which version of Nav? 2009 or 2013?
    – Mak Sim
    Nov 20, 2013 at 11:49
  • the version is 2009 R2 Nov 20, 2013 at 12:09
  • Need more info I believe. Tried to reproduce it, can't. My VS2010 generates only first of version of the field (the one with names Open, Release, etc.) Maybe something wrong with the page you are publishing. I've tested it with page 42 which is based on Sales Header same as yours.
    – Mak Sim
    Nov 21, 2013 at 6:32
  • @MakSim thank you very much for your test, the table is the Sales Header (36) but the Page is a custom one (due to an integration it's not possible to use the standard one), but this error happens also with enum from other pages published to the WEb Services (Form 810) Nov 21, 2013 at 7:32
  • 2
    Here is a big thread about this issue: social.msdn.microsoft.com/Forums/en-US/…. But the gist is that your service provides a malformed wsdl and the add service reference silently falls back from DataContract serialization to XML seriliazation which messes up the generated classes. Use svcutil with the /serializer:DataContractSerializer option and it will tell you what is the problem with your wsdl.
    – nemesv
    Nov 22, 2013 at 21:04

6 Answers 6

8
+500

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)

3
  • Hi @Alex, thanks for you reply. 1) there are no other enums, I started an empty project to avoid also these issues 2) Web Reference create working code, but I need to use these WS from Service Reference 3) I will try to create the proxy using svcutil, can you please provide a complete command line as example? thank you very much Nov 22, 2013 at 10:40
  • I expanded the answer
    – Alex
    Nov 22, 2013 at 10:58
  • with your workaround (to use svcutil) I solved my problem, now I can have a proxy without duplicated definitions (need to fix namespaces and app.config but are small things). Because the question is why the standard service reference generate the duplicates, I will keep open the question for 7 days for possible answers, but if no other one comes out I will set your as accepted and give you the bounty. Thank you again! Nov 22, 2013 at 12:38
6

Here is what fixed it for me:

  1. Add the service reference as you normally would
  2. In the "Solution explorer", choose toggle the "Show all files" icon
  3. Open the Reference.svcmap of the service reference you just added
  4. Change the line <Serializer>Auto</Serializer>
  5. To <Serializer>XmlSerializer</Serializer>
  6. Update the service reference

It seems that in some versions of Visual Studio the "Add service reference" feature is not able to automatically determine whether to use XmlSerializer og DataContractSerializer. So the above forces it to use XmlSerializer.

3
  • thanks for your answer. I don't know when I can try your solution but I will post my results. Aug 26, 2015 at 4:35
  • Sweet! Thanks for your answer. I was migrating old projects to vs2015 and got tons of errors. This answer has fixed all my issues.
    – Louis
    Mar 3, 2017 at 15:06
  • Worked great. Awesome suggestion! Jan 27, 2020 at 23:58
2

I know it has been awhile for this question but just in case anyone else is encountering a similar issue:

When adding a ServiceReference to your VS project it is important to use the exact url related to the web service you have exposed-- ie:

Do not discover all web service objects by entering:

http://navserver.domain.com:7047/DynamicsNAV/WS/services

and then selecting the web service object from the list.

Instead reference the web service object specifically as in:

http://navserver.domain.com:7047/DynamicsNAV/WS/%PercentEncodedCompanyNameHere%/page/salesheaderpage

This should save you the trouble of deleting the extra references.

This is not an issue when adding a Web Reference to your project it is unique to ServiceReferences

0

I have seen this problem before, and it happened when I had a WPF application and a WCF service sharing a common assembly as a means of serializing / deserializing data between them.

The problem seemed to result from the fact that the common assembly had a different name to its project name.

This was a while back, so my memory is somewhat hazy, but I believe I renamed the assembly to match the project name, and then it worked fine.

Apparently, it's been reported by other users here.

Does this match your situation?

0

This may be helpful to someone. I was adding the postcodeanywhere service to an application and kept getting the same sort of error. I changed the IIS Application Pool to allow 32 bit and it instantly started working. I have no idea why this should be the case but it worked for me.

0

I recommend always keeping the service reference in a DLL of its own so it's easier to undo changes. The 'svcutil' is 'old' now and sometimes gets confused.

Here's my story...

I have been using this service reference for YEARS and updating it mostly without ussue. I needed theBinary type from System.Data.Linq so I checked that assembly.

enter image description here

Somehow it got completely confused and created an additional Reference1.cs which duplicated EVERYTHING in Reference.cs (you can see it is a new file because of the +).

enter image description here

Even when I did Undo pending changes to try to revert it the extra file remained without the + symbol, but I still got duplicates.

enter image description here

I ended up having to completely delete the reference and recreate it.

As I said it is much safer to create a separate project/DLL for your service reference so when things go haywire (rare but does happen) that you can fix it more easily.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.