How to pass multiple parameter in wcf restful service?

前端 未结 3 537
故里飘歌
故里飘歌 2020-12-08 16:07

IService.cs

[OperationContract]
[WebGet(UriTemplate = \"/IsValidUser?userid={userid}&password={password}\", RequestFormat = WebMessageFo         


        
相关标签:
3条回答
  • 2020-12-08 16:41

    you can write this way:

    Iservice.cs

    [OperationContract]
    [WebGet(UriTemplate = "IsValidUser/{userid}/{password}")]
    string IsValidUser(string userid, string password);
    

    service .cs

    public string IsValidUser(string userid, string password)
    {
       if (userid== "root" && password== "root")
       {
          return "True";
       }
       else
       {
          return "false";
       }    
    }
    

    Run this Url in Browser,then you will get output localhost/service.svc/rest/IsValidUser/root/root

    0 讨论(0)
  • 2020-12-08 16:47

    Add BodyStyle on OperationContract

    [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
    
    0 讨论(0)
  • 2020-12-08 16:52

    try this

    [OperationContract]
    [WebGet(UriTemplate = "IsValidUser?userid={userid}&password={password}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    string IsValidUser(string userid, string password);
    
    0 讨论(0)
提交回复
热议问题