简体   繁体   English

HTTP / 1.1 415无法处理消息,因为内容类型为'application / json; charset = utf-8'不是预期的类型'text / xml; 字符集= UTF-8'

[英]HTTP/1.1 415 Cannot process the message because the content type 'application/json; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'

trying to POST json dictionary to C# WCF, when i invoke it HTTP Response 415. Someone can tell me whats wrong with my code. 尝试将json字典发布到C#WCF,当我调用HTTP响应415时。有人可以告诉我我的代码有什么问题。

object Class 对象类

 [DataContract]
public class Class1
{
    [DataMember]
    public string AccNo;
     [DataMember]
    public string CompanyName;
     [DataMember]
    public string DocDate;
}

IService1.cs IService1.cs

   [OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "json/PostSalesOrderData", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
        string PostSalesOrderData(string data);

Service1.svc.cs Service1.svc.cs

 public string PostSalesOrderData(string data)
    {

        JavaScriptSerializer serializer = new JavaScriptSerializer();

        Dictionary<string, Class1> dict = serializer.Deserialize<Dictionary<string, Class1>>(data);

        return dict["Debtor"].AccNo.ToString();
    }

Fiddle Details 小提琴细节

HTTP/1.1 415 Cannot process the message because the content type 'application/json; HTTP / 1.1 415无法处理消息,因为内容类型为'application / json; charset=utf-8' was not the expected type 'text/xml; charset = utf-8'不是预期的类型'text / xml; charset=utf-8'. 字符集= UTF-8' 。 Server: Microsoft-IIS/7.5 X-Powered-By: ASP.NET Date: Thu, 29 Nov 2012 01:21:55 GMT Content-Length: 0 服务器:Microsoft-IIS / 7.5 X-Powered-By:ASP.NET日期:星期四,2012年11月29日01:21:55 GMT内容长度:0

The endpoint for your service is not properly configured to receive JSON input. 您的服务端点未正确配置为接收JSON输入。 In order for the [WebInvoke] attribute to be honored, your endpoint needs to have the webHttpBinding , and it should also have an endpoint behavior of type <webHttp/> 为了使[WebInvoke]属性得到遵守,您的端点需要具有webHttpBinding ,并且它还应具有类型为<webHttp/>的端点行为

One easy way to ensure that it's properly configured is to use the Factory attribute on the .svc file. 确保正确配置的一种简单方法是使用.svc文件上的Factory属性。 Something like the example below: 类似下面的例子:

<%@ ServiceHost Language="C#" Debug="true"
                Service="YourNamespace.YourServiceClass"
                Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 HTTP 415 无法处理消息,因为内容类型为“application/json; charset=utf-8&#39; 不是预期的类型 &#39;text/xml; 字符集=utf-8&#39; - HTTP 415 Cannot process the message because the content type 'application/json; charset=utf-8' was not the expected type 'text/xml; charset=utf-8' 无法处理消息,因为内容类型为 &#39;application/json; charset=utf-8&#39; 不是预期的类型 &#39;text/xml; 字符集=utf-8&#39; - Cannot process the message because the content type 'application/json; charset=utf-8' was not the expected type 'text/xml; charset=utf-8' 无法处理该消息,因为内容类型“ application / xml”不是预期的类型“ application / soap + xml”; 字符集= utf-8&#39; - Cannot process the message because the content type 'application / xml' was not the expected type 'application / soap + xml; charset = utf-8 ' 响应消息的内容类型application / xml; charset = utf-8与绑定的内容类型不匹配(text / xml; charset = utf-8) - The content type application/xml;charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8) 响应消息的内容类型 application/xml;charset=utf-8 与绑定的内容类型(text/xml; charset=utf-8)不匹配,WCF - The content type application/xml;charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8), WCF 内容类型 text/xml; 响应消息的 charset=&quot;utf-8&quot; 与绑定的内容类型不匹配 (text/xml; charset=utf-8) - The content type text/xml; charset=“utf-8” of the response message does not match the content type of the binding (text/xml; charset=utf-8) 内容类型text / html; charset =响应消息的UTF-8与绑定的内容类型不匹配(text / xml; charset = utf-8) - The content type text/html; charset=UTF-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8) WCF错误:(415)内容类型&#39;application / x-www-form-urlencoded&#39;不是预期类型&#39;application / soap + xml; 字符集= UTF-8&#39; - WCF ERROR: (415) content type 'application/x-www-form-urlencoded' was not the expected type 'application/soap+xml; charset=utf-8' WCF成员资格提供程序引发错误:内容类型&#39;application / json; charset = utf-8&#39;不是预期的类型&#39;application / soap + xml; 字符集= UTF-8&#39; - WCF Membership Provider throws error: content type 'application/json; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8' WCF SOAP服务无法处理该消息,因为它发送多部分消息并且需要&#39;text / xml; charset = utf-8&#39; - WCF SOAP service cannot process the message because it sends multipart message and expects 'text/xml; charset=utf-8'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM