【问题标题】:WCF method post json return bad requestWCF方法post json返回错误请求
【发布时间】:2013-11-22 10:39:06
【问题描述】:

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

谁能告诉我为什么当我用这个名字发帖时,它给了我不好的要求?

问候

【问题讨论】:

    标签: c# json wcf


    【解决方案1】:

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

    尝试删除Method = "POST"

    【讨论】:

      猜你喜欢
      • 2017-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多