简体   繁体   中英

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. GET/POST works on my local IIS. However on the server POSTS gives me the following error:

The incoming HTTP request's URI ' http://myserver:9002/StudyService.svc/rest/RestAuthenticateUser ' does not match any service operation.

[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

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

I am looking into .net installs on the server. I am thinking that maybe it is more of a environment issue instead of a coding?

Target framework: .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.

You either pass some of the parameters in the URI string

[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)
{
    ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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