tags:

views:

1077

answers:

2

I'm creating a WCF Client to an External REST API, but are getting the following error:

OperationFormatter encountered an invalid Message body

The client hits the server correctly and does the 'Post' that I am requiring, but it is expecting a different response Element, basically appending 'Response' to the name of the OperationContract's Name, such as:

OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'companyResponse' and namespace ''. Found node type 'Element' with name 'company' and namespace ''

Does anybody know how to make it remove the requirement for 'Response' to be added to the name?

Additional Details (I added ReplyAction but it did not make a difference):

[OperationContract(Name="company", Action = "company", ReplyAction = "company")]
        [WebInvoke(
        Method = "POST",
        BodyStyle = WebMessageBodyStyle.WrappedResponse,
        ResponseFormat = WebMessageFormat.Xml,
        UriTemplate = "companies.xml"
        )]
        Company AddCompany(Company company);
A: 

It would help if you posted the contract definition that you were using. Generally though, you are going to have to set the Name property on the OperationContractAttribute instance that you attach to the method on the contract that you are trying to call, and possibly the Action and ReplyAction properties as well.

casperOne
A: 

The BodyStyle in the operation contract has been set to WrappedResponse. Change the BodyStyle to WebMessageBodyStyle.Bare.

This tells the WCF runtime not to include the wrapper which is an XML node with the Name= MethodName+ the word "Response"

Prashanth