我正在使用一个httpclient实例发送多个请求来休息web api以获取数据.这是我的代码的样子:
首先,我有一个控制层,用于调用数据的数据层.
public class ControlLayer
{
protected DataLayer dal;
//constructors here
public int getInfo1(int param)
{
int ret = this.dal.getInfo1(param);
return ret;
}
public int getInfo2(int param)
{
int ret = this.dal.getInfo2(param);
return ret;
}
}
Run Code Online (Sandbox Code Playgroud)
然后我有调用webAPI的dataLayer,它看起来像这样.这里为了简单起见,我直接使用.result.
public class DataLayer
{
HttpClient client = new HttpClient();
string url = "";
public int getInfo1(int param1)
{
int ret=0;
HttpResponseMessage response = client.GetAsync(url).Result;
//.... do some work, get the value for ret
return ret;
}
public int getInfo2(int param1)
{
int …Run Code Online (Sandbox Code Playgroud)