0
嗨,大家好我有這個代碼被創建爲一個Web服務,問題是WebRequest.Create,它似乎是一個Web服務沒有創建方法,什麼可以我做的解決方法?謝謝。這是我的整個代碼。如何在Web服務上調用WebReqeuest.Create
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Net;
using System.IO;
using System.Net.NetworkInformation;
using System.Text;
namespace ApplicationMonitoring.Service
{
/// <summary>
/// Summary description for WebRequest
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class WebRequest : System.Web.Services.WebService
{
[WebMethod]
public string WebReq(string url,int timeout)
{
try
{
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create(url);
request.Proxy = new System.Net.WebProxy("10.80.50.60:8080", true);
request.Timeout = timeout;
//request.Proxy.Credentials = CredentialCache.DefaultCredentials;
// execute the request
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
response.StatusCode.ToString();
}
catch (WebException ex)
{
Response.Write(((HttpWebResponse)ex.Response).StatusCode);
}
}
}
}
你面臨什麼問題? – 2012-07-20 05:31:07
嗨,我需要能夠發送一個webrequest到一個特定的網址來檢查它的狀態,無論它是否正常運行,我的問題是\t'Test.Service.WebRequest'沒有包含'Create'的定義。 – anonymous1110 2012-07-20 05:36:15
我更新了我的答案 – 2012-07-20 05:55:20