0

Coming to new to WebAPI and i am having a namespace issue

I have a POST method in my WebAPI that accepts an object as JSON or XML however the method is to be consumed by a BizTalk service which adds its own namespace to the xml.

<ns0:Person xmlns:ns0="http://Acme/Esb/DestinationSchemas/Person/v1.0">
  <WorkEmail>Someemail@acme.com</WorkEmail>
  <PersonId>10</PersonId>
  <UserName>Shouldhaveone</UserName>
</ns0:Person>

and my WebAPI Post method is defined as follows

<Person xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <PersonId>10</PersonId>
  <WorkEmail>Someemail@acme.com</WorkEmail>
  <UserName>Shouldhaveone</UserName>
</Person>

As you can see the namespaces are different and whenever the Post called the object is null. Can someone please advise me of the best approach to ignore the namespaces of incoming requests

Many thanks

2 Answers2

0

Option 1 is to switch to using XmlSerializer in GlobalConfiguration:

config.Formatters.XmlFormatter.UseXmlSerializer = true;

Option 2 is to decorate your models with

[DataContract(Namespace="")]

(and if you do so, you'd need to decorate the members with [DataMember] attributes).

original post Remove namespace in XML from ASP.NET Web API

Community
  • 1
  • 1
ahmed
  • 7
  • 5
0

The answer was to add XmlMediaFormatter to ignore namespaces

all thanks to Jan Jonas

http://blog.janjonas.net/2012-09-07/asp_net-mvc_4_rc-web-api-implementing-custom-xmlmediatypeformatter-ignore-xml-namespace