大家好,我有这个代码要创建为 Web 服务,问题出在 WebRequest.Create,似乎 Web 服务没有创建方法,我能做些什么作为解决方法?谢谢。这是我的整个代码。
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);
}
}
}
}