Reputation: 601
I'm hoping this is an easy question. I haven't made a public api using webapi or a restful service before. So I have noticed that when creating a Put or Post method that use a complex object parameter the xml sent in the body is required to contain namespace info. For example.
public HttpResponseMessage Put(Guid vendortoken, [FromBody] ActionMessage message)
{
if (message == null)
return Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed,
"actionmessage must be provided in request body.");
return Request.CreateResponse(HttpStatusCode.OK);
}
For message to come back not null my request has to look like this.
<ActionMessage
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.datacontract.org/2004/07/IntegrationModels">
<Message i:type="NewAgreement">
<AgreementGuid>3133b145-0571-477e-a87d-32f165187783</AgreementGuid>
<PaymentMethod>Cash</PaymentMethod>
</Message>
<Status>0</Status>
</ActionMessage>
the key here of course is the xmlns. On one hand the namespace is pretty generic so I feel like it shouldn't be an issue for vendors to provide, on the other hand should they really need to? If not how can I fix this so message will come back populated if they leave the name space out?
ah if only I could make them all use json :(
Upvotes: 0
Views: 415
Reputation: 87228
The namespace is significant in XML. If you want to remove it, what you can do is to change your ActionMessage
class, to annotate it with the appropriate attribute (in your case, I'm assuming it would be the [DataContract(Namespace="")]
), and that should remove the need for the namespace in the input (actually, after making that change using the namespace would be an error, so please consider the implications if you already have clients using your API out there).
Upvotes: 1