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 6769905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:14:56+00:00 2026-05-26T15:14:56+00:00

I am using a client app to connect to a web service for authenticated

  • 0

I am using a client app to connect to a web service for authenticated user only. Here is simplest example:
My web service code:

public class TestService : System.Web.Services.WebService
{
    [WebMethod(EnableSession = true)]
    public string WelcomeMsg()
    {
        return "Hello: " + Session["UserName"] + "! Welcome to our store.";
    }

    [WebMethod(EnableSession = true)]
    public void SetUserName(string sName)
    {
        Session["UserName"] = sName;
    }
}

Here is my code on client app (Windows form, not web base):

private void btnSetName_Click(object sender, EventArgs e)
{
    TestService.TestService ws = new TestService.TestService(); //Create a web service
    MainForm.m_ccSessionInfo = new System.Net.CookieContainer(); //Create a CookieContainer
    ws.CookieContainer = MainForm.m_ccSessionInfo; //Set CookieContainer of the web service
    ws.SetUserName(txtUserName.Text); //Set value of session 
    ws = null;
}

private void btnWelcome_Click(object sender, EventArgs e)
{
    TestService.TestService ws = new TestService.TestService(); //Create a web service
    ws.CookieContainer = MainForm.m_ccSessionInfo; //Set CookieContainer back
    string sWelcome = ws.WelcomeMsg(); //Get value from session property
    ws = null;

    System.Diagnostics.Debug.WriteLine(sWelcome); 
}

In my example MainForm.m_ccSessionInfo is a static member, I want to keep the session cookies value in this one!
However, it don’t work 🙁 . The ws.WelcomeMsg() is always return an empty string.

  • 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-26T15:14:56+00:00Added an answer on May 26, 2026 at 3:14 pm

    Oops, I think I’ve just found the solution for this problem. The CookieContainer is created by server and must be kept at client app. On btnSetName_Click, I change

    MainForm.m_ccSessionInfo = new System.Net.CookieContainer(); //Create a CookieContainer
    ws.CookieContainer = MainForm.m_ccSessionInfo; //Set CookieContainer of the web service
    

    into

    ws.CookieContainer = new System.Net.CookieContainer(); //Create a CookieContainer
    MainForm.m_ccSessionInfo = ws.CookieContainer; //Keep CookieContainer for later using
    

    And it works well now! Thanks you all.

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

Sidebar

Related Questions

I`m writing client-server app for windows using WinSock and I have class for server.
Using SubSonic v2.3 in a web app. Each client (200+) will have their own
I'm creating a multi-tenant Asp.Net MVC 3 Web app, and using EF4.1 code first
I'm writing a client-server app using BSD sockets. It needs to run in the
Using the client and server examples found here: http://www.winsocketdotnetworkprogramming.com/winsock2programming/winsock2advancedmailslot14.html Compiling them with VS2008, running
I'm using VisualSVN client and server and one of the requirements for web projects
Having successfully got a WCF service and client to talk to one another using
May i achieve that server side application (using android bluetooth API)connect to particular client
I am following this instructions in order to connect my app engine python web
I have a client that connects to a WCF service using a netTcpBinding .

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.