Web services POST方法HTML表单的RestFull WCF服务

Web services POST方法HTML表单的RestFull WCF服务,web-services,wcf,rest,Web Services,Wcf,Rest,我创建了一个RestFul WCF Web服务,并部署了它。我可以使用GET方法数据,但不能使用POST方法数据,它总是向我提供错误的请求响应 [OperationContract] [WebInvoke(Method = "POST", UriTemplate = "BookAppointment")] AppointmentBookAndCancelResult BookAppointment(AppointmentBookAndCancelInPu

我创建了一个RestFul WCF Web服务,并部署了它。我可以使用GET方法数据,但不能使用POST方法数据,它总是向我提供错误的请求响应

     [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "BookAppointment")]
        AppointmentBookAndCancelResult BookAppointment(AppointmentBookAndCancelInPut input);
这是我的这个RestFul WCF服务的HTML表单

<form enctype="multipart/form-data" action="http://192.168.15.45:8083/TaqeemServices.svc/BookAppointment" Method="POST">

 <input name="AppointmentNumber" type="text" value="APP-00000003-H042S5"/>
<input name="UserId" type="text" value="4"/>

    <input type="submit" />
</form> 
根据Shah的说法,我已经在web.config文件中创建了这个方法,当我运行post方法时,我得到了详细的输出

The server encountered an error processing the request. 
The exception message is 'The incoming message has an unexpected message format 'Raw'. 
The expected message formats for the operation are 'Xml', 'Json'. 
This can be because a WebContentTypeMapper has not been configured on the binding. 
See the documentation of WebContentTypeMapper for more details.'. 
See server logs for more details. The exception stack trace is: 

at System.ServiceModel.Dispatcher.DemultiplexingDispatchMessageFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.CompositeDispatchFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

WCF Web服务使用与Json或XML表示一起工作的WebHttpBinding。在您的情况下,您发送的数据sthm如下所示:

-----------------------------7de175231090e00
Content-Disposition: form-data; name="AppointmentNumber"

APP-00000003-H042S5
-----------------------------7de175231090e00
Content-Disposition: form-data; name="UserId"

4 
-----------------------------7de175231090e00--

这绝对不是json或xml表示。

我无法确切地告诉您出了什么问题,但我可以以WCF跟踪日志的形式为您提供一些帮助。如果按照说明操作,您将能够看到正在发生的错误以及与之相关的所有调用堆栈信息。也许到时候您可以给我们提供更多的细节,甚至可以在没有任何进一步指导的情况下解决问题!:-请发布AppointmentBook和CancelInput的代码。请将这些代码添加到您的web.config并刷新@Shah。我已经做了更改,并且我已经用更改后收到的输出更新了我的问题。似乎我必须以xml格式传递数据,但什么样的过程是正确的,但如何以xml表示形式发送数据?将数据发送和编码委托给ECMAScript JS,或者在服务器操作中使用流,并将该流解码委托给服务器。
The server encountered an error processing the request. 
The exception message is 'The incoming message has an unexpected message format 'Raw'. 
The expected message formats for the operation are 'Xml', 'Json'. 
This can be because a WebContentTypeMapper has not been configured on the binding. 
See the documentation of WebContentTypeMapper for more details.'. 
See server logs for more details. The exception stack trace is: 

at System.ServiceModel.Dispatcher.DemultiplexingDispatchMessageFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.CompositeDispatchFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
-----------------------------7de175231090e00
Content-Disposition: form-data; name="AppointmentNumber"

APP-00000003-H042S5
-----------------------------7de175231090e00
Content-Disposition: form-data; name="UserId"

4 
-----------------------------7de175231090e00--