views:

120

answers:

1

To comply with a clients schema, I've been attempting to generate a WCF client proxy capable of serializing down to a structure with a root node that looks like the following:

<quote:request
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:quote="https://foo.com/services/schema/1.2/car_quote"&gt;

After some reading, I've had luck in updating the proxy to include the required 'quote' namespace through the use of XmlNameSpaceDeclarations and XmlSerializerNamespaces

[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class request
{
    [XmlNamespaceDeclarations()]
    public XmlSerializerNamespaces xmlsn
    {
        get
        {
            XmlSerializerNamespaces xsn = new XmlSerializerNamespaces();
            xsn.Add("quote", "https://foo.com/services/schema/1.2/car_quote");
            return xsn;
        }
        set
        {
            //Just provide an empty setter. 
        }
    }
    ...

which delivers:

<request
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:quote="https://foo.com/services/schema/1.2/car_quote"&gt;

however I'm stumped as to how to generate the quote:request element.

Environment: ASP.NET 3.5

Thanks

A: 

I can't really reproduce your situation without some WSDL to generate a proxy from, but the serialization bit works for me if I add an XmlRoot attribute.

using System.Xml.Serialization;

[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[XmlRoot(Namespace="https://foo.com/services/schema/1.2/car_quote")]
public partial class request
{
    get 
    {
        [XmlNamespaceDeclarations()]
        public XmlSerializerNamespaces xmlsn
        {
            XmlSerializerNamespaces xsn = new XmlSerializerNamespaces();
            xsn.Add("quote", "https://foo.com/services/schema/1.2/car_quote");
            return xsn;
        }
    } 
    set { }
}
Thorarin