I have an existing WCF Web API app that is registering routes using the following pattern:
RouteTable.Routes.Add(new ServiceRoute("MyService", new WebServiceHostFactory(), typeof(MyServiceImplementation)));
I recently updated to Preview 6. I also updated the registration pattern in Global.asax to use the enhancements extension:
routes.SetDefaultHttpConfiguration(new MyServiceConfiguration());
routes.MapServiceRoute<MyServiceImplementation>("MyService");
I also have a contract that I am posting to a method in a request.
[WebInvoke(UriTemplate = "/MyOperation", Method = "POST")]
Contact MyOperation(Contact contact);
...
[DataContract( Name = "Contact" )]
public class Contact : IExtensibleDataObject
{
[StringLength(50)]
[StringNotEmpty]
[DataMember(Name = "FirstName", Order = 1)]
public string FirstName { get; set; }
[DataMember(Name = "LastName", Order = 1)]
public string LastName { get; set; }
//[StringLength(50)]
//[DataMember(Name = "Location", Order = 1)]
//public String Location { get; set; }
public ExtensionDataObject ExtensionData { get; set; }
}
The issue I am getting is that when I post a previously acceptable contract, such as:
<Contact xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://myservice/schema">
<FirstName>John</FirstName>
<LastName>Smith</LastName>
<Location i:nil="true" />
</Contact>
I get the following exception:
The server encountered an error processing the request. Please see the service help page for constructing valid requests to the service. The exception message is 'The service operation 'MyOperation' expected a value assignable to type 'Contact' for input parameter 'contact' but received a value of type 'HttpRequestMessage`1'.'. See server logs for more details.
I found that if I remove the xmlns="http://myservice/schema" from my request, the service accepts the request. I have existing api clients that will be making calls to the new service with this present, so I have to make sure these messages are accepted.
I understand that the WCF Web Api Enhancements (extension method) I am using uses different classes under the hood; but I am a little ignorant at the moment as to why one would be able to deserialize and the other would not.
Cheers.