Trying to write a WCF interface that handles Json requests (and responses). Have written the following
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest,
ResponseFormat = WebMessageFormat.Json)]
MyRequestResponse MyRequest(MyRequestType request);
public partial class MyRequestType
{
[JsonProperty(Required = Required.Always)]
public string id;
}
public partial class MyRequestResponse
{
public string dummyRes = "A response of sorts.";
}
with the following in web.config
<service name="emuse.Chooser.Provide.ChooserWCF.ChooserQueryService" behaviorConfiguration="JsonServiceBehaviour">
<endpoint address="" binding="webHttpBinding" contract="emuse.Chooser.Provide.ChooserWCF.IChoosQueryerQueryService"
behaviorConfiguration="JsonEndpointBehaviour" />
</service>
<serviceBehaviors>
<behavior name="JsonServiceBehaviour">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="JsonEndpointBehaviour">
<enableWebScript />
</behavior>
</endpointBehaviors>
I'm using the following to test it initially
curl -X POST http://localhost/Chooser/ChooserQueryService.svc/MyRequest -H 'Content-Type:application/json' -H 'Accept:application/json' -d '{"id":1}'
But I'm getting The incoming message has an unexpected message format 'Raw'. The expected message formats for the operation are 'Xml', 'Json'
I've searched for various answers for this and they generally come down to ensuring that I'm passing 'Content-Type:application/json' and that I've got BodyStyle = WebMessageBodyStyle.WrappedRequest.
Any ideas what I'm doing wrong?
CodePudding user response:
Turns out there was nothing wrong with code or configuration - using Postman it succeeded.
I've no idea why curl failed.