VS2010 confuses System.Xml.XmlElement with System.Xml.Linq.XElement?

前端 未结 3 1229
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-10 14:50

I have created a WCF service with one method which returns a System.Xml.XmlElement:

Interface:

[ServiceContract]
public         


        
相关标签:
3条回答
  • 2020-12-10 15:30

    I hate to answer my own question, but here it goes:

    As far as I can see, the System.Xml.XmlElement CAN be used as a return type for a WCF service. The DataContractSerializer used by default in WCF does support this type and thus it shouldn't be necessary to use the XmlSerializer.

    However my problem has nothing to do with serializing, but thanks to Raj Kaimal for suggesting this possibility.

    I followed the WCF tutorials given by Microsoft, which tells you to add the WCF service as a Service Reference when you want to use the service. This seems to be okay in VS2008, but when switching to VS2010 this approach changes the return type from System.Xml.XmlElement to the (newer?) System.Xml.Linq.XElement. To solve this, you need to add the service as a Web Reference instead.

    0 讨论(0)
  • 2020-12-10 15:43

    1) Remove the system.xml.linq reference from your client 2) Update your service reference 3) The re-generated Reference.cs file will now reference XmlElement instead of XElement

    0 讨论(0)
  • 2020-12-10 15:47

    What I have found works the best and easiest for me is to right-click on the service reference and then click on "Configure Service Reference". Once in the dialog box for this at the bottom you will see 2 radio buttons that say "Reuse types in all referenced assemblies" or "Reuse types in specified referenced assemblies". Click on the 2nd option for 'specified assemblies'. The listbox will then be enabled and you can check all assemblies and leave System.Xml.Linq unchecked. This way every time you update the service reference you will get the expected results and this will be stored in the configuration of the client.

    0 讨论(0)
提交回复
热议问题