Forcing WCF proxy to generate an alias prefix
- by Sean Campbell
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