![](/img/trans.png)
[英]POST request to WCF REST (json) - WebException (400) bad request
[英]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.