gpt4 book ai didi

WCF 服务错误 - 传入消息具有意外的消息格式 'Raw'。预期的消息格式为 'Xml' , 'Json'

转载 作者:行者123 更新时间:2023-12-04 05:06:49 26 4
gpt4 key购买 nike

我想将 jason 格式的数据发送到 wcf 服务进行处理。开发了 Wcf 服务,当使用 fiddler 将 jason 输入发送到服务时,它会抛出错误 -
服务器在处理请求时遇到错误。异常消息是“传入消息具有意外消息格式“原始”。该操作的预期消息格式为“Xml”、“Json”。这可能是因为尚未在绑定(bind)上配置 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

如果我使用 wcftestclient( Debug模式),它工作正常 - 猜测它使用的是 soap/xml。

最佳答案

请求的内容类型应为 application/ json ,而不是应用程序/杰森。尝试改变它,它应该工作。

关于WCF 服务错误 - 传入消息具有意外的消息格式 'Raw'。预期的消息格式为 'Xml' , 'Json',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26123619/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com