How can I add a XML prefix to fields in WCF Message Serialization?
I'm connecting up to a Java Spring web service from .NET, and an object that I pass in with parameters is being serialized as you would expect:
<MyClass>
<field1>Field 1 Value</field1>
<field2>Field 2 Value</field2>
</MyClass>
However, the web service requires that the class and fields are prefixed with a namespace, let's say namespace blah
, so what I want is:
<blah:MyClass>
<blah:field1>Field 1 Value</blah:field1>
<blah:field2>Field 2 Value</blah:field2>
</blah:MyClass>
How can I make this happen in WCF? Is there a way to adjust the XML serialization attributes on my class?
Edit: WSDL for this particular entity is as follows (edited to remove business-specific field names, but everything else is the same):
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:sch0="http://www.domain.com/app/schemas/entityone" xmlns:sch1="http://www.domain.com/app/schemas/types" xmlns:sch2="http://www.domain.com/app/schemas/query" xmlns:sch3="http://www.domain.com/app/schemas/entitytwo" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.domain.com/app/schemas/entityone" targetNamespace="http://www.domain.com/app/schemas/entityone">
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:types="http://www.domain.com/app/schemas/types" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://www.domain.com/app/schemas/entityone" xmlns:tns="http://www.domain.com/app/schemas/entityone">
<import namespace="http://www.domain.com/app/schemas/types" />
<element name="TheClassName">
<complexType>
<sequence>
<element name="field1" type="string" />
<element name="field2" type="string" />
<element name="field3" type="string" />
<element name="field4" type="string" />
<element name="field5" type="string" />
<element name="field6" type="string" />
<element name="field7" type="string" />
<element name="field8" type="string" />
</sequence>
</complexType>
</element>
<wsdl:binding name="NameOfBindingHere" type="tns:ReturnTypeHere">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="OperationNameHere">
<soap:operation soapAction="" />
<wsdl:output name="ResponseTypeHere">
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>