繁体   English   中英

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

[英]WCF method post json return bad request

我在这里遇到无法解决的问题。 我正在用ajax和json进行发布以通过WCF传递数据,但不起作用...给了我错误的请求。 我不知道我在做什么错...

我的代码是这样

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:

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);
 }
}

谁能告诉我为什么当我写这个名字的帖子时却提出了错误的要求?

问候

我相信您正在创建两个GET方法而不是POST。

尝试删除Method = "POST"

暂无
暂无

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

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