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

时间:2013-11-22 10:39:06

标签: c# json wcf

我遇到了一个我无法解决的问题。 我正在用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);
 }
}

任何人都可以告诉我为什么当我使用这个名字发帖时,它给了我错误的请求?

问候

1 个答案:

答案 0 :(得分:0)

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

尝试删除Method = "POST"

相关问题