C# 如何在 WCF Rest Service 中传递多个参数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9381633/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to pass multiple parameters in WCF Rest Service?
提问by kasun tharanga
I'm developing WCF REST service in C#. It works fine for a single parameter. Now I need to extend it to support multiple parameters. Please help me on this issue.
我正在用 C# 开发 WCF REST 服务。它适用于单个参数。现在我需要扩展它以支持多个参数。请帮助我解决这个问题。
Thanks in advance...
提前致谢...
Use following declaration in interface:
在接口中使用以下声明:
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Xml,
RequestFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.WrappedRequest,
UriTemplate = "login")]
resLogin Login(reqLogin rData, int floorId);
回答by SliverNinja - MSFT
Take a look at UriTemplate parameters. You can use the QueryString or URL path to pass in the floorIdparameter.
看看UriTemplate 参数。您可以使用 QueryString 或 URL 路径来传递floorId参数。
URI Path Parameter
URI 路径参数
[WebInvoke(Method = "POST", UriTemplate = "login/floor/{floorId}")]
resLogin Login(reqLogin rData, int floorId);
QueryString Parameter
查询字符串参数
[WebInvoke(Method = "POST", UriTemplate = "login?floorId={floorId}")]
resLogin Login(reqLogin rData, int floorId);
回答by Ankit
Add BodyStyle on OperationContract
在 OperationContract 上添加 BodyStyle
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest)]

