如何在wcf restful服务中传递多个参数?
IService.cs
[OperationContract] [WebGet(UriTemplate = "/IsValidUser?userid={userid}&password={password}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] string IsValidUser(string userid, string password);
Service.cs
public string IsValidUser(string userid, string password) { if (userid =="bob" && password =="bob") { return "True"; } else { return "false"; } }
web.config中
问题:
这里我的问题是我想在调用WCFrest服务时传递多个参数,但我无法将多个参数传递给该WCFrest服务。 我想传递用户ID和密码并检查它。 如果它是bob然后允许继续。
当我打电话给这个url时:
https://localhost:48401/ARService/Service.svc/rest/IsValidUser?userid=bob&password=bob
然后我在我的网页上收到此错误:
端点未找到。 请参阅服务帮助页面以构建对服务的有效请求。
如果有人知道如何使用此函数参数调用IsValidUser
。 请帮我。
你可以这样写:
Iservice.cs
[OperationContract] [WebGet(UriTemplate = "IsValidUser/{userid}/{password}")] string IsValidUser(string userid, string password);
服务.cs
public string IsValidUser(string userid, string password) { if (userid== "root" && password== "root") { return "True"; } else { return "false"; } }
在浏览器中运行此Url,然后您将获得输出localhost / service.svc / rest / IsValidUser / root / root
试试这个
[OperationContract] [WebGet(UriTemplate = "IsValidUser?userid={userid}&password={password}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] string IsValidUser(string userid, string password);
在OperationContract上添加BodyStyle
上述就是C#学习教程:如何在wcf restful服务中传递多个参数?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/1011996.html