WCF服务错误-传入消息具有意外的消息格式“原始".预期的消息格式为"Xml","Json" [英] WCF service error - Incoming message has an unexpected message format 'Raw'. Expected message formats are 'Xml', 'Json'

查看:130
本文介绍了WCF服务错误-传入消息具有意外的消息格式“原始".预期的消息格式为"Xml","Json"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将jason格式的数据发送到wcf服务进行处理. Wcf服务已开发,当使用fiddler将jason输入发送到该服务时,它将引发错误- 服务器在处理请求时遇到错误.异常消息是传入消息的消息格式为意外的原始".该操作的预期消息格式为"Xml","Json".这可能是因为尚未在绑定上配置WebContentTypeMapper.有关更多详细信息,请参见WebContentTypeMapper的文档.有关更多详细信息,请参见服务器日志.

I want to send data in jason format to a wcf service for processing. Wcf service is developed and when jason input is sent to the service using fiddler, it throws the error - 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.

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

如果我使用wcftestclient(调试模式),则可以正常工作-猜猜它使用了soap/xml.

If I use wcftestclient (debug mode), it works fine - guess it uses soap/xml.

推荐答案

请求的内容类型应为application/ json ,而不是application/ jason .尝试更改它,它应该可以工作.

The content type of the request should be application/json, not application/jason. Try changing that and it should work.

这篇关于WCF服务错误-传入消息具有意外的消息格式“原始".预期的消息格式为"Xml","Json"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆