[英]WCF Rest Service POSTS on local IIS but not on server (GET works in both)
我有一個WCF服務,已經添加了RESTful支持。 GET / POST在我的本地IIS上有效。 但是在服務器上,POSTS給我以下錯誤:
傳入的HTTP請求的URI'http:// myserver:9002 / StudyService.svc / rest / RestAuthenticateUser '與任何服務操作都不匹配。
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "/RestAuthenticateUser", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
authResultDTO RestAuthenticateUser(AuthRequest authRequest);
public authResultDTO RestAuthenticateUser(AuthRequest authRequest)
{
...
}
我通過郵遞員發布: http:// myserver:9002 / StudyService.svc / rest / RestAuthenticateUser
content-type: application/json
body: raw JSON
{
"DomainName": "Local",
"UserID": "myuser",
"Password": "mypassword"
}
我正在研究服務器上的.net安裝。 我認為這可能更多是環境問題,而不是編碼?
目標框架:.Net Framework 4.5
任何想法如何解決這個問題?
僅GET方法允許多個參數,POST僅允許將一個參數作為請求的主體傳遞。
您可以在URI字符串中傳遞一些參數
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "/RestAuthenticateUser/{userID}/{password}/{applicationId}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
authResultDTO RestAuthenticateUser(AuthRequest authRequest);
public authResultDTO AuthenticateUser(string domainName, string userID, string password, string applicationId)
{
...
}
或者您使用數據合同
[DataContract(Namespace="http://yournamespace.com")]
public class MyContract
{
[DataMember(Order=1)]
public string DomainName { get(); set{};}
[DataMember(Order=2)]
public string UserID { get(); set{};}
...
}
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "/RestAuthenticateUser", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
authResultDTO RestAuthenticateUser(AuthRequest authRequest);
public authResultDTO AuthenticateUser(MyContract contract)
{
...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.