Forcing WCF proxy to generate an alias prefix

Posted by Sean Campbell on Stack Overflow See other posts from Stack Overflow or by Sean Campbell
Published on 2010-06-11T05:47:33Z Indexed on 2010/06/11 5:52 UTC
Read the original article Hit count: 304

Filed under:
|
|

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">

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">

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

Environment: ASP.NET 3.5

Thanks

© Stack Overflow or respective owner

Related posts about c#

Related posts about wcf