我想以jason格式将数据发送到wcf服务进行处理.开发了Wcf服务,当使用fiddler将jason输入发送到服务时,它会抛出错误 - 服务器在处理请求时遇到错误.异常消息是'传入消息具有意外的消息格式'Raw'.操作的预期消息格式是'Xml','Json'.这可能是因为尚未在绑定上配置WebContentTypeMapper.有关更多详细信息,请参阅WebContentTypeMapper的文档.请参阅服务器日志以获取更多详
Service contract
================
public interface IRegisterEmployee
{
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, BodyStyle=WebMessageBodyStyle.Bare, ResponseFormat=WebMessageFormat.Json, UriTemplate = "AddEmployee")]
bool ProcessEmployee(Employee emp);
}
[DataContract]
public class Employee
{
[DataMember]
public string emp { get; set; } //this is actually a complex type, but simplified here
}
Service class
============
public class RegisterEmployee : IRegisterEmployee
{
public bool ProcessEmployee(Employee emp)
{
//do some processing
return true;
}
Web.config
=========
<services>
<service name="Project.RegisterEmployee">
<endpoint address="Rest" behaviorConfiguration="RestfulBehavior" binding="webHttpBinding" name="Rest" contract="Project.IRegisterEmployee" />
<endpoint address="Soap" behaviorConfiguration="" binding="basicHttpBinding" name="Soap" contract="Project.IRegisterEmployee" />
<endpoint address="Mex" behaviorConfiguration="" binding="mexHttpBinding" name="Mex" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/Project" />
</baseAddresses>
</host>
</service>
</services>
<endpointBehaviors>
<behavior name="RestfulBehavior">
<webHttp automaticFormatSelectionEnabled="true" />
</behavior>
</endpointBehaviors>
*Fiddler
======
POST; http://localhost/Project/RegisterEmployee.svc/Rest/AddEmployee
Content-Type: application/jason
Request Body = {"emp" : "test"}*
Error - HTTP/1.1 400 Bad Request
Run Code Online (Sandbox Code Playgroud)
如果我使用wcftestclient(调试模式),它工作正常 - 猜它使用soap/xml.
| 归档时间: |
|
| 查看次数: |
19622 次 |
| 最近记录: |