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

  • SEARCH
  • Home
  • 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 1044999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:55:04+00:00 2026-05-16T15:55:04+00:00

I am a complete ASP .NET newbie. I’ve written a set of web services

  • 0

I am a complete ASP .NET newbie. I’ve written a set of web services using the WCF 4 Rest Starter Kit. I call everything from within a Flash application but I want to write a quick and dirty admin panel for myself to use which has no need to be written in Flash.

I figure it will be faster to get this up and running in ASP. So the question is consider a WCF function like this:

[WebInvoke(UriTemplate = "/Login/", Method = "POST")]
        public User Login(User user)
        {
             // Code here
             // Either throw a WebFaultException or return the logged in user with a session id

How would I consume this from an ASP .Net page with a username, password, submit box and it either displays errors 401’s etc or success (returneduser.sessionid).

Thanks!

Note:
I am aware of how to call a Rest service over Http in C#. It’s really a question of is there a “nice way” to due this in ASP or is it just make a form like:

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<form action="WebForm2.aspx.cs" >
    <asp:textbox id="Email" runat="server"/>
    <asp:textbox id="Password" runat="server"/>
    <asp:Button id="Button1" OnClick="OnButtonClick" runat="server" Text="Login"/>
  </form>
  <asp:Label ID="labelResult" runat="server" />
</asp:Content>

Then on click in the code behind do something like this:

 protected  void OnButtonClick(object sender, EventArgs e)
        {
            HttpWebRequest req = WebRequest.Create("http://localhost:35810/Users/Login/") as HttpWebRequest;

            String userString = UsefulStuff.Serialization.SerializationUtil.
                SerializeDataContractToString(typeof(User), new User() { Email =  new Email(textboxUsername.text),
                                                                         Password = new Password(textboxPassword.text) });

            String strResponse = GetHttpPostResponse(req, userString);

            User recievedUser = UsefulStuff.Serialization.SerializationUtil.DeserializeDataContractString(
                typeof(User), strResponse) as User;

            labelResult.Text = recievedUser.SessionId;
        }


        public static String GetHttpPostResponse(HttpWebRequest httpWebRequest, String serializedPayload)
        {
            httpWebRequest.Method = "POST";
            httpWebRequest.ContentType = "text/xml";
            httpWebRequest.ContentLength = serializedPayload.Length;

            StreamWriter streamOut = new StreamWriter(httpWebRequest.GetRequestStream(), Encoding.ASCII);
            streamOut.Write(serializedPayload);
            streamOut.Close();

            StreamReader streamIn = new StreamReader(httpWebRequest.GetResponse().GetResponseStream());

            string strResponse = streamIn.ReadToEnd();
            streamIn.Close();

            return strResponse;
        }
  • 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-05-16T15:55:05+00:00Added an answer on May 16, 2026 at 3:55 pm

    Basic approach to call REST service is by HttpWebRequest

    // User object serialized to XML
    XElement data = new XElement("User",
      new XElement("UserName", UserName),
      new XElement("Password", Password)
    );
    
    MemoryStream dataSream = new MemoryStream();
    data.Save(dataStream);
    
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(YourServiceUrl);
    request.Method = "POST";
    request.ContentType = "application/xml";
    // You need to know length and it has to be set before you access request stream
    request.ContentLength = dataStream.Length; 
    
    using (Stream requestStream = request.GetRequestStream())
    {
      dataStream.CopyTo(requestStream);   
      requestStream.Close();
    } 
    
    HttpWebResponse response = request.GetResponse();
    if (response.Status == HttpStatusCode.Unauthorized)
    {
      ...
    }
    else
    {
      ...
    }
    response.Close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bit of experience in creating web applications using asp.net however I
I'm writing an ASP.NET web service using C# that has a DoLookup() function. For
I'm a newbie in asp.net mvc. I need to create a 'auto-complete tag search'
I have the authentication portion of an ASP.NET 3.5 web application complete. I would
AJAX newbie here! At the moment in my ASP.NET MVC web app my AJAX
I have an ASP.NET MVC web application that makes REST style web service calls
Experienced .Net developer but a complete ASP MVC (and web dev in general) novice.
I am using the example at The Complete Guide To Validation In ASP.NET MVC
I'm using jquery file upload to upload images to asp.net server (http://www.webtrendset.com/2011/06/22/complete-code-example-for-using-blueimp-jquery-file-upload-control-in-asp-net/) I need
My ASP.NET MVC application is using Application Services for Membership. For a number of

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.