简体   繁体   English

WCF方法发布json返回错误的请求

[英]WCF method post json return bad request

I'm here with a problem I can not solve. 我在这里遇到无法解决的问题。 I'm doing a post with ajax and json to pass data by WCF, but does not work ... gives me bad request. 我正在用ajax和json进行发布以通过WCF传递数据,但不起作用...给了我错误的请求。 I do not know what I'm doing wrong ... 我不知道我在做什么错...

My code is this 我的代码是这样

Service1.svc.cs: Service1.svc.cs:

namespace Teste
 {

public class Service1 : IService1
{
    public string GetData()
    {
        string getdata = "hello";
        return string.Format("You entered" + getdata);
    }
    public string GetDataName(string Name)
    {
        return string.Format("You entered" + Name);
    }
}
}

IService1.cs: IService1.cs:

namespace Teste
{
[ServiceContract]
public interface IService1
{

    [OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "GetData", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
    string GetData();

    [OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "GetDataName", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
    string GetDataName(string Name);
 }
}

Can anyone tell me why when I do the post with the name, it gives me bad request? 谁能告诉我为什么当我写这个名字的帖子时却提出了错误的要求?

greetings 问候

I believe you are creating two GET methods rather than POST. 我相信您正在创建两个GET方法而不是POST。

Try removing Method = "POST" . 尝试删除Method = "POST"

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM