使用接受三个类作为条目的Web服务

时间:2015-06-26 07:42:49

标签: c# web-services rest

我想使用接受三个类作为入口参数的Web服务。我有这种方法来创建请求和响应:

private T SendDataToServer<T>(string endpoint, string method, T pun)
{
    var request = (HttpWebRequest)HttpWebRequest.Create(endpoint);
    request.Accept = "application/json";
    request.ContentType = "application/json";
    request.Method = method;
    var serializer = new DataContractJsonSerializer(typeof(T));
    var requestStream = request.GetRequestStream();
    serializer.WriteObject(requestStream, pun);
    requestStream.Close();
    var response = request.GetResponse();
    if (response.ContentLength == 0)
    {
        response.Close();
        return default(T);
    }
    var responseStream = response.GetResponseStream();
    var responseObject = (T)serializer.ReadObject(responseStream);
    responseStream.Close();
    return responseObject;
}

这项工作很好。但这种方法只适用于一个类。如何向Web服务发送三个类? 谢谢

0 个答案:

没有答案