POST方法HTML表单的RestFull WCF服务



我创建了一个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> 

我总是得到这样的错误响应:

<body>
    <div id="content">
      <p class="heading1">Request Error</p>
      <p>The server encountered an error processing the request. See server logs for more details.</p>
    </div>
  </body>

怎么了?

预约簿和取消输入代码:

 [DataContract]
    public class AppointmentBookAndCancelInPut
    {
        string userId = string.Empty;
        string appointmentNumber = string.Empty;
        [DataMember]
        public string UserId
        {
            get { return userId; }
            set { userId = value; }
        }
        [DataMember]
        public string AppointmentNumber
        {
            get { return appointmentNumber; }
            set { appointmentNumber = value; }
        }
    }

根据Shah的说法,我在web.config文件中制作了<serviceDebug includeExceptionDetailInFaults="true"/>,当我运行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表示。

最新更新