简体   繁体   English

C#中的宁静Web服务具有多个Get with param

[英]Restful web service in c# that has multiple Get with param

I need to have 2 Gets in my rest web service the first Get takes 5 parameters, while the 2nd one takes 7 different parameters 我需要在其余的Web服务中拥有2个Gets,第一个Get需要5个参数,而第二个需要7个不同的参数

I know that we can have default Get without parameters but how can we have 2 Gets with both have parameters? 我知道我们可以有不带参数的默认Get,但是我们怎么有两个都带参数的Get?

thanks 谢谢

both gets are needed 都需要

    public string Get(Int64 id, string UserID, int Val1, int Val2, int Val3)
{
}

    public int Get(string FirstName, string LastName, int Age, int Tall, int Size, string Code, string Address)
{
}

you can use the following tips if you want 您可以根据需要使用以下提示

// GET: api/Default
public IEnumerable<string> Get( string p1, string p2, string p3, string p4, string p5, string p6=null,string p7=null)
{

    return new string[] { "value1", "value2" };
}

if you pass 5 arguments your 6 and 7 will be null or 7 arguments with same action 如果您传递5个参数,则您的6和7将为null或具有相同操作的7个参数

Or you can define 2 gets like the following 或者您可以定义2个如下所示的获取

// GET: api/Default
public IEnumerable<string> Get( string p1, string p2, string p3, string p4, string p5)
{

    return new string[] { "value1", "value2" };
}

and 7 parameters 和7个参数

// GET: api/Default
public IEnumerable<string> Get( string p1, string p2, string p3, string p4, string p5, string p6,string p7)
{

    return new string[] { "value1", "value2" };
}

you have to use the following uri for example 您必须使用以下uri为例

http://localhost:53383/api/default?p1=tes&p2=tesff&p3=tes&p4=tesffs&p5=tesffs

and for the action with 7 parameters 对于具有7个参数的操作

http://localhost:53383/api/default?p1=tes&p2=tesff&p3=tes&p4=tesffs&p5=tesffs&p6=tesp6&p7=tesp7

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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