Go To StackoverFlow.com

0

When I run my WCF REST method from the browser I receive a: in front of xml elements in when returning WCF REST service in browser? Anyone ever see this and know why it could occur? I was expecing formatted elements

<?xml version="1.0"?>
<GetProductNameListResponse xmlns="TheBigContract">
<GetProductNameListResult xmlns:i="http://www.w3.org/2001/XMLSchemaintance" xmlns:a="http://schemas.datacontract.org/2004/07/ProductDTO">

<a:Product>
<a:Company i:nil="true"/>
<a:DayOfWeek i:nil="true"/>
<a:Location i:nil="true"/>
<a:TimeOfDay i:nil="true"/>
<a:TruckID>0</a:TruckID>
<a:TruckName>BBQ Smith</a:TruckName>
<a:Website>test</a:Website>
</a:Product>

<a:Product>
<a:Company i:nil="true"/>
<a:DayOfWeek i:nil="true"/>
<a:Location i:nil="true"/>
<a:TimeOfDay i:nil="true"/>
<a:TruckID>0</a:TruckID>
<a:TruckName>Bon Me</a:TruckName>
<a:Website>test</a:Website>
</a:Product>
2012-04-05 15:55
by midnightCoder


0

That is still valid XML. Your inner elements are defined in http://schemas.datacontract.org/2004/07/ProductDTO name space and this is the way how valid XML uses elements from multiple name spaces in the same XML document. Do you see that xmlns:a=... in GetProductNameListResult? That defines prefix (alias) for that name space. Only elements from single name space can be without prefix (that is called default name space).

Edit: Name spaces define container where element and attribute names must be unique. But you can have multiple element types with the same name in the same XML document if they are from different name spaces. It is similar concept to .NET name spaces.

2012-04-05 15:59
by Ladislav Mrnka
So are you saying if I had 1 unique namespace then I would not see the a:? thanks - midnightCoder 2012-04-05 16:12
Yes it can be the case but it depends on XML serializer if it uses default namespace or explicitly use named namespace - Ladislav Mrnka 2012-04-05 16:23
In your case, I don't believe you can get down to a single namespace because you have "nullable" properties like Company that must be defined in soap by using the nil="true" from the XmlSchemaInstance namespace - Sixto Saez 2012-04-05 16:31
One last question do you think this will cause issues when say consuming from C# or javascript - midnightCoder 2012-04-05 16:36