Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8260381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:05:15+00:00 2026-06-08T03:05:15+00:00

Hi guys i have this code to be created as a web service, the

  • 0

Hi guys i have this code to be created as a web service, the problem is with WebRequest.Create, it seems that a web service doesn’t have a create method, what can I do as a workaround? thanks. Here’s my entire code.

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);

        }

    }
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T03:05:16+00:00Added an answer on June 8, 2026 at 3:05 am

    In your code HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); creates a webService.

    you can refer this link http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx

    Here is the code to create an instance of webRequest.

    using System;
    using System.IO;
    using System.Net;
    using System.Text;
    
    namespace Examples.System.Net
    {
        public class WebRequestGetExample
        {
          public static void Main ()
          {
            // Create a request for the URL.        
            WebRequest request = WebRequest.Create ("http://www.contoso.com/default.html");
            // If required by the server, set the credentials.
            request.Credentials = CredentialCache.DefaultCredentials;
            // Get the response.
            HttpWebResponse response = (HttpWebResponse)request.GetResponse ();
            // Display the status.
            Console.WriteLine (response.StatusDescription);
            // Get the stream containing content returned by the server.
            Stream dataStream = response.GetResponseStream ();
            // Open the stream using a StreamReader for easy access.
            StreamReader reader = new StreamReader (dataStream);
            // Read the content.
            string responseFromServer = reader.ReadToEnd ();
            // Display the content.
            Console.WriteLine (responseFromServer);
            // Cleanup the streams and the response.
            reader.Close ();
            dataStream.Close ();
            response.Close ();
           }
         }
       }
    

    now to create a webService request you just have to use the

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    make sure you have included required header file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

HI Guys, I have created a web service. And I m able to hit
I have a problem with .Net's RichTextBox control. It seems that it doesn't support
hey guys having this really simple problem but cant seem to figure out have
Hey guys I simply cannot get this to work. I have some content that
Can you guys help me figure this out? I have the following JavaScript snippet:
Ok guys, I have a serious problem with this. I have a static class
I have a very dynamic web app that is dynamically created controls at run-time.
Hey guys, I have this piece of jquery code: <script type=text/javascript > $(function() {
I have this extension method I created and it returns a string of all
I have a function that is generating XML for a contract last web service(not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.