简体   繁体   English

WCF Rest Service POSTS在本地IIS上但不在服务器上(GET在两种情况下均有效)

[英]WCF Rest Service POSTS on local IIS but not on server (GET works in both)

I have a WCF service that I have added RESTful support to. 我有一个WCF服务,已经添加了RESTful支持。 GET/POST works on my local IIS. GET / POST在我的本地IIS上有效。 However on the server POSTS gives me the following error: 但是在服务器上,POSTS给我以下错误:

The incoming HTTP request's URI ' http://myserver:9002/StudyService.svc/rest/RestAuthenticateUser ' does not match any service operation. 传入的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)
{
    ...
}

I am posting through Postman: http://myserver:9002/StudyService.svc/rest/RestAuthenticateUser 我通过邮递员发布: http:// myserver:9002 / StudyService.svc / rest / RestAuthenticateUser

content-type: application/json
body: raw      JSON
{
    "DomainName": "Local",
    "UserID": "myuser",
    "Password": "mypassword"
}

I am looking into .net installs on the server. 我正在研究服务器上的.net安装。 I am thinking that maybe it is more of a environment issue instead of a coding? 我认为这可能更多是环境问题,而不是编码?

Target framework: .Net Framework 4.5 目标框架:.Net Framework 4.5

Any idea how to solve this? 任何想法如何解决这个问题?

Only the GET method allows multiple parameters, POST allows only one parameter passed as the body of the request. 仅GET方法允许多个参数,POST仅允许将一个参数作为请求的主体传递。

You either pass some of the parameters in the URI string 您可以在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)
{
    ...
}

Or you use a data contract 或者您使用数据合同

[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.

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