Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass multiple parameters in WCF Rest Service?

Tags:

c#

wcf

service

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.

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);
like image 369
kasun tharanga Avatar asked Feb 21 '12 16:02

kasun tharanga


2 Answers

Take a look at UriTemplate parameters. You can use the QueryString or URL path to pass in the floorId parameter.

URI Path Parameter

[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);
like image 58
SliverNinja - MSFT Avatar answered Oct 09 '22 05:10

SliverNinja - MSFT


Add BodyStyle on OperationContract

[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
like image 29
Ankit Avatar answered Oct 09 '22 04:10

Ankit