locked
Using web service reference got strange compilation error RRS feed

  • Question

  • Hello.

    I used several link to web services in project. Had no problem until today I got some new link and after compiling code got an error in code autogenerated by visualstudio.

    this is two conflicting definitions:

    1

    /// <remarks/>

            [System.Xml.Serialization.XmlElementAttribute(Order=1)]

            public string id {

                get {

                    return this.idField;

                }

                set {                                // here we got error reference

                    this.idField = value;

                    this.RaisePropertyChanged("id");

                }

            }

    2

    /// <remarks/>

            [System.Xml.Serialization.XmlElementAttribute(Order=4)]

            public string set_id {

                get {

                    return this.set_idField;

                }

                set {

                    this.set_idField = value;

                    this.RaisePropertyChanged("set_id");

                }

            }

    Ошибка 1 Класс "virtualVasilySokolov.Anubis.Item" уже содержит определение для "set_id" \\psf\Home\Documents\Visual Studio 2013\Projects\virtualVasilySokolov\virtualVasilySokolov\Service References\Anubis\Reference.cs 1348 13 virtualVasilySokolov

    Friday, June 19, 2015 10:56 AM

Answers

  • The setter of the "id" property is named set_id and you also have a property named set_id.

    That's quite unfortunate but there's not much you can do if you want to continue using autogenerated service references, you need to change the name of the set_id property in the web service.

    If that's not possible then you'll have to manually modify the autogenerated file and change the name of the set_id property to something else. To keep serialization working you have to add ElementName = "set_id" to the XmlElementAttribute of the set_id property.

    • Marked as answer by vbmchik Friday, June 19, 2015 11:49 AM
    Friday, June 19, 2015 11:07 AM

All replies

  • The setter of the "id" property is named set_id and you also have a property named set_id.

    That's quite unfortunate but there's not much you can do if you want to continue using autogenerated service references, you need to change the name of the set_id property in the web service.

    If that's not possible then you'll have to manually modify the autogenerated file and change the name of the set_id property to something else. To keep serialization working you have to add ElementName = "set_id" to the XmlElementAttribute of the set_id property.

    • Marked as answer by vbmchik Friday, June 19, 2015 11:49 AM
    Friday, June 19, 2015 11:07 AM
  • Thank you a lot! Got just stuck in the middle of the day... Thank you!
    Friday, June 19, 2015 11:50 AM
  •  <xs:element name="id" type="xs:string" />

    This I got from wsdl generated after connection to service.

    So, I changed id, but nothing happened...

    I am not very familiar with WEB service references complete structure.

    Maybe I must edit some other files?

    Friday, June 19, 2015 12:37 PM
  • Hmm, you're not supposed to change the WSDL directly, you should change the web service itself, provide that you have control over it.
    Friday, June 19, 2015 2:15 PM
  • web service is external one... Okey, I can use direct parsing soap xml..

    Thank you again!!! 

    Have a nice day

    Friday, June 19, 2015 2:17 PM
  • "Okey, I can use direct parsing soap xml.."

    Well, I suppose you could do that too but it's likely simpler to edit the Reference.cs file generated by Visual Studio. I suppose that earlier that when mentioned editing the WSDL that's what you were trying to do but you really only need to edit the .cs file. Something like:

            [System.Xml.Serialization.XmlElementAttribute(Order=4, ElementName="set_id")]
            public string setid {
                get {
                    return this.set_idField;
                }
                set {
                    this.set_idField =  value;
                    this.RaisePropertyChanged("setid");
                }
            }
    
    You can give whatever name you want to that property as long the XmlElementAttribute mentions the real name of the XML element.

    Friday, June 19, 2015 2:20 PM