.Net webservice動的呼び出し
3907 ワード
直接コードを貼りましょう
交流したいqq連絡:1576410833
public class PmsService
{
/// <summary>
/// pms
/// </summary>
/// <param name="invokeBaseData"> </param>
/// <returns> </returns>
public string InvokeService(InvokeBaseData invokeBaseData)
{
string result = "", tempUrl = "", content = "";
tempUrl = "http://115.238.104.156:5031/XRself/HepInterface_Service.asmx/WebConnector";
content = "v=" + invokeBaseData.Version + "&n=" + invokeBaseData.Number +
"&f=" + invokeBaseData.Function + "&q=" + invokeBaseData.QueryString +
"&c=" + invokeBaseData.ClientInfo + "&s=" + invokeBaseData.State;
StreamReader myStreamReader;
var bs = Encoding.UTF8.GetBytes(content);
var request = (HttpWebRequest)HttpWebRequest.Create(tempUrl);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = bs.Length;
try
{
using (Stream reqStream = request.GetRequestStream())
{
reqStream.Write(bs, 0, bs.Length);
reqStream.Close();
}
var wr = request.GetResponse();
var myResponseStream = wr.GetResponseStream();
myStreamReader = new StreamReader(myResponseStream);
result = myStreamReader.ReadToEnd();
}
catch (WebException ce)
{
var res = (HttpWebResponse)ce.Response;
try
{
myStreamReader = new StreamReader(res.GetResponseStream());
result = myStreamReader.ReadToEnd();
}
catch (Exception e)
{
result = ce.Message;
}
}
return result;
}
}
交流したいqq連絡:1576410833