none
namespace prefix not being appended by WCF proxy while sending request to svc service RRS feed

  • Question

  • Hey Guys,

    We are consuming svc services being offered by one of the API providers as such. We created proxy of svc using svcutil (as c sharp class). There is one property that is defined as below in the proxy class:

    [System.Xml.Serialization.XmlArrayItemAttribute(Namespace = "http://schemas.microsoft.com/2003/10/Serialization/Arrays")]
    
    public string[] PClasses
            {
                get
                {
                    return this.pClassesField;
                }
                set
                {
                    this.pClassesField = value;
                }
            }



    Now the server is expecting the xml as below:

    <PClasses>
                  <arr:string>ABC</arr:string>
                  <arr:string>DEF</arr:string>
    </PClasses>

    However when we try to intercept the request using fiddler the request xml being sent by our proxy is like below:

    <PClasses>
            <string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">ABC</string>
            <string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">DEF</string>
          </PClasses>

    The svc service finds the above xml incorrect and ignores it resulting in wrong response. 

    Can anyone point out how we can add <arr: prefix to this list (array of string)? Or is there anything that we are missing while generating the proxy class itself.

    Your help shall be greatly appreciated.

    Thanks

    Pawan


    Best Regards
    solidroots

    Wednesday, November 6, 2019 2:52 PM

All replies

  • Hi,

    The serialization structure is not precisely controlled by the WCF default serializer, so we can only add namespaces. 

    public class Product
        {
            public int ID { get; set; }
            public string Name { get; set; }        
            [XmlArray(Namespace ="ArrayNameSpace")]
            [XmlArrayItem(Namespace ="ItemNamespace")]
            public string[] Description
            {
                get;set;
            }
        }
    

    As far as I know, for communicating with the java server, the prefix in serialization does not matter.
    If you serialize manually, you can refer to the following example to add a prefix.

    https://social.msdn.microsoft.com/Forums/en-US/fec3247e-6efa-401a-8f31-573d7d7b6860/xmlserializer-in-wcf-namespace-prefix-?forum=wcf

    Welcome to share your solution with me, thank you.
    Feel free to let me know if there is anything I can help with.
    Best Regards
    Abraham

    Thursday, November 7, 2019 6:51 AM
    Moderator