Connecting Tech Pros Worldwide Forums | Help | Site Map

How to get a WS to create a cookie???

=?Utf-8?B?SlA=?=
Guest
 
Posts: n/a
#1: Feb 26 '07
I need to design a WS that will after authenicating the user, create a cookie
on the users PC that made the request. All the code I keep finding is how to
get a WS to read a cookie, I need it to create one. The below code doesnt add
the cookie to my cache. However if I place this in an non asmx page its fine

Any help you offer is apperiated

[WebMethod(EnableSession=true)]
public string CreateToken(string User, string App, string County)
{
//Do some stuff
....
....

HttpCookie myCookie = new HttpCookie("NameMaster");
myCookie.Domain = "mydomain.com";
myCookie["ID"] = Result.ToString();
myCookie["User"] = User;
myCookie["App"] = App;
myCookie["County"] = County;
myCookie.Expires = DateTime.Now.AddMinutes(30);
HttpContext.Current.Response.Cookies.Add(myCookie) ; //doesnt work
--
JP
..NET Software Developer

Joseph Geretz
Guest
 
Posts: n/a
#2: Feb 26 '07

re: How to get a WS to create a cookie???


Hi JP,
Quote:
HttpContext.Current.Response.Cookies.Add(myCookie) ; //doesnt work
What do you mean it doesn't work? Do you get an error, or you're just not
seeing the Cookie on the successive request for the next the Web Service
method? If the latter, you ned to set up your WS Proxy on the client to
handle cookies. We enventually settled on using SOAP header, rather than a
cookie, so I don't have live code to demonstrate this, but if I recall
correctly, you need to code something like

m_WSProxyClass.CookieContainer = new System.Net.CookieContainer();

So that your proxy will now have access to cookies for the purpose of
receiving and sending.

If this doesn't do it for you, I will see if I can dig up some old code from
when we were using cookies. We did manage to get it to work and so should
you.

Standard caveat applies: If your Web Services are going to rely on coookies,
you will be limited to HTTP clients. Other clients which don't support the
cookie mechanism won't be able to use your services.

Hope this helps,

Joseph Geretz

"JP" <JP@discussions.microsoft.comwrote in message
news:7713F4F9-7A6C-43F9-BA6D-39981234BABE@microsoft.com...
Quote:
>I need to design a WS that will after authenicating the user, create a
>cookie
on the users PC that made the request. All the code I keep finding is how
to
get a WS to read a cookie, I need it to create one. The below code doesnt
add
the cookie to my cache. However if I place this in an non asmx page its
fine
>
Any help you offer is apperiated
>
[WebMethod(EnableSession=true)]
public string CreateToken(string User, string App, string County)
{
//Do some stuff
...
...
>
HttpCookie myCookie = new HttpCookie("NameMaster");
myCookie.Domain = "mydomain.com";
myCookie["ID"] = Result.ToString();
myCookie["User"] = User;
myCookie["App"] = App;
myCookie["County"] = County;
myCookie.Expires = DateTime.Now.AddMinutes(30);
HttpContext.Current.Response.Cookies.Add(myCookie) ; //doesnt work
--
JP
.NET Software Developer

=?Utf-8?B?SlA=?=
Guest
 
Posts: n/a
#3: Feb 26 '07

re: How to get a WS to create a cookie???


my apoligies for not clarifying. The code does not error out. I just dont get
the cookie in my cache.
--
JP
..NET Software Developer


"Joseph Geretz" wrote:
Quote:
Hi JP,
>
Quote:
HttpContext.Current.Response.Cookies.Add(myCookie) ; //doesnt work
>
What do you mean it doesn't work? Do you get an error, or you're just not
seeing the Cookie on the successive request for the next the Web Service
method? If the latter, you ned to set up your WS Proxy on the client to
handle cookies. We enventually settled on using SOAP header, rather than a
cookie, so I don't have live code to demonstrate this, but if I recall
correctly, you need to code something like
>
m_WSProxyClass.CookieContainer = new System.Net.CookieContainer();
>
So that your proxy will now have access to cookies for the purpose of
receiving and sending.
>
If this doesn't do it for you, I will see if I can dig up some old code from
when we were using cookies. We did manage to get it to work and so should
you.
>
Standard caveat applies: If your Web Services are going to rely on coookies,
you will be limited to HTTP clients. Other clients which don't support the
cookie mechanism won't be able to use your services.
>
Hope this helps,
>
Joseph Geretz
>
"JP" <JP@discussions.microsoft.comwrote in message
news:7713F4F9-7A6C-43F9-BA6D-39981234BABE@microsoft.com...
Quote:
I need to design a WS that will after authenicating the user, create a
cookie
on the users PC that made the request. All the code I keep finding is how
to
get a WS to read a cookie, I need it to create one. The below code doesnt
add
the cookie to my cache. However if I place this in an non asmx page its
fine

Any help you offer is apperiated

[WebMethod(EnableSession=true)]
public string CreateToken(string User, string App, string County)
{
//Do some stuff
...
...

HttpCookie myCookie = new HttpCookie("NameMaster");
myCookie.Domain = "mydomain.com";
myCookie["ID"] = Result.ToString();
myCookie["User"] = User;
myCookie["App"] = App;
myCookie["County"] = County;
myCookie.Expires = DateTime.Now.AddMinutes(30);
HttpContext.Current.Response.Cookies.Add(myCookie) ; //doesnt work
--
JP
.NET Software Developer
>
>
>
=?Utf-8?B?SlA=?=
Guest
 
Posts: n/a
#4: Feb 26 '07

re: How to get a WS to create a cookie???


Users (progrmmers) will use this service to create a GUID. This GUID along
with other related information will be stored in a cookie on local machine so
that our application can authenicate admin requests using the cookie
information. This is why the cookie is only valid for 30 mins per request
--
JP
..NET Software Developer


"Joseph Geretz" wrote:
Quote:
Hi JP,
>
Quote:
HttpContext.Current.Response.Cookies.Add(myCookie) ; //doesnt work
>
What do you mean it doesn't work? Do you get an error, or you're just not
seeing the Cookie on the successive request for the next the Web Service
method? If the latter, you ned to set up your WS Proxy on the client to
handle cookies. We enventually settled on using SOAP header, rather than a
cookie, so I don't have live code to demonstrate this, but if I recall
correctly, you need to code something like
>
m_WSProxyClass.CookieContainer = new System.Net.CookieContainer();
>
So that your proxy will now have access to cookies for the purpose of
receiving and sending.
>
If this doesn't do it for you, I will see if I can dig up some old code from
when we were using cookies. We did manage to get it to work and so should
you.
>
Standard caveat applies: If your Web Services are going to rely on coookies,
you will be limited to HTTP clients. Other clients which don't support the
cookie mechanism won't be able to use your services.
>
Hope this helps,
>
Joseph Geretz
>
"JP" <JP@discussions.microsoft.comwrote in message
news:7713F4F9-7A6C-43F9-BA6D-39981234BABE@microsoft.com...
Quote:
I need to design a WS that will after authenicating the user, create a
cookie
on the users PC that made the request. All the code I keep finding is how
to
get a WS to read a cookie, I need it to create one. The below code doesnt
add
the cookie to my cache. However if I place this in an non asmx page its
fine

Any help you offer is apperiated

[WebMethod(EnableSession=true)]
public string CreateToken(string User, string App, string County)
{
//Do some stuff
...
...

HttpCookie myCookie = new HttpCookie("NameMaster");
myCookie.Domain = "mydomain.com";
myCookie["ID"] = Result.ToString();
myCookie["User"] = User;
myCookie["App"] = App;
myCookie["County"] = County;
myCookie.Expires = DateTime.Now.AddMinutes(30);
HttpContext.Current.Response.Cookies.Add(myCookie) ; //doesnt work
--
JP
.NET Software Developer
>
>
>
Joseph Geretz
Guest
 
Posts: n/a
#5: Feb 26 '07

re: How to get a WS to create a cookie???


Hi JP,

Have a look at the Cache object. The Cache object is a server side store
with much of the same functionality as cookies have. So you can place data
in the Cache and it will expire after a certain period of time, just as a
cookie does. Instead of using a cookie to shuttle data back and forth, the
data remains on the server in the cache, keyed by GUID for example, and you
can use a SOAP header to shuttle the GUID back and forth between client and
server on each request.

Your earlier comment about not seeing the cookie in the cache is consistent
with the fact that you haven't created a cookiecontainer on the client to
maintain the cookie (see my earlier response).

Hoep this helps,

- Joseph Geretz -

"JP" <JP@discussions.microsoft.comwrote in message
news:7CBB4FF4-3DF2-4020-880D-D72D8153DD9D@microsoft.com...
Quote:
Users (progrmmers) will use this service to create a GUID. This GUID along
with other related information will be stored in a cookie on local machine
so
that our application can authenicate admin requests using the cookie
information. This is why the cookie is only valid for 30 mins per request
--
JP
.NET Software Developer
>
>
"Joseph Geretz" wrote:
>
Quote:
>Hi JP,
>>
Quote:
HttpContext.Current.Response.Cookies.Add(myCookie) ; //doesnt work
>>
>What do you mean it doesn't work? Do you get an error, or you're just not
>seeing the Cookie on the successive request for the next the Web Service
>method? If the latter, you ned to set up your WS Proxy on the client to
>handle cookies. We enventually settled on using SOAP header, rather than
>a
>cookie, so I don't have live code to demonstrate this, but if I recall
>correctly, you need to code something like
>>
>m_WSProxyClass.CookieContainer = new System.Net.CookieContainer();
>>
>So that your proxy will now have access to cookies for the purpose of
>receiving and sending.
>>
>If this doesn't do it for you, I will see if I can dig up some old code
>from
>when we were using cookies. We did manage to get it to work and so should
>you.
>>
>Standard caveat applies: If your Web Services are going to rely on
>coookies,
>you will be limited to HTTP clients. Other clients which don't support
>the
>cookie mechanism won't be able to use your services.
>>
>Hope this helps,
>>
>Joseph Geretz
>>
>"JP" <JP@discussions.microsoft.comwrote in message
>news:7713F4F9-7A6C-43F9-BA6D-39981234BABE@microsoft.com...
Quote:
>I need to design a WS that will after authenicating the user, create a
>cookie
on the users PC that made the request. All the code I keep finding is
how
to
get a WS to read a cookie, I need it to create one. The below code
doesnt
add
the cookie to my cache. However if I place this in an non asmx page its
fine
>
Any help you offer is apperiated
>
[WebMethod(EnableSession=true)]
public string CreateToken(string User, string App, string County)
{
//Do some stuff
...
...
>
HttpCookie myCookie = new HttpCookie("NameMaster");
myCookie.Domain = "mydomain.com";
myCookie["ID"] = Result.ToString();
myCookie["User"] = User;
myCookie["App"] = App;
myCookie["County"] = County;
myCookie.Expires = DateTime.Now.AddMinutes(30);
HttpContext.Current.Response.Cookies.Add(myCookie) ; //doesnt work
--
JP
.NET Software Developer
>>
>>
>>

John Saunders
Guest
 
Posts: n/a
#6: Feb 27 '07

re: How to get a WS to create a cookie???


"Joseph Geretz" <jgeretz@nospam.comwrote in message
news:eQyvSFfWHHA.488@TK2MSFTNGP06.phx.gbl...
Quote:
Hi JP,
....
Quote:
Standard caveat applies: If your Web Services are going to rely on
coookies, you will be limited to HTTP clients. Other clients which don't
support the cookie mechanism won't be able to use your services.
In fact, not all HTTP clients will support cookies.

Depending on what you mean to use the cookie for, you might do better with a
SOAP header.

John


Scott M.
Guest
 
Posts: n/a
#7: Feb 27 '07

re: How to get a WS to create a cookie???


Cookies are created by the client (browser). As such, it wouldn't make any
sense for a web service to attempt to create a cookie because it is one step
removed from the correct source for cookies, the web server.

Client ---web page --a web service

See how the service is not the right place for this. The code to create the
cookie should be in the page/code that calls the cookie.


"JP" <JP@discussions.microsoft.comwrote in message
news:7713F4F9-7A6C-43F9-BA6D-39981234BABE@microsoft.com...
Quote:
>I need to design a WS that will after authenicating the user, create a
>cookie
on the users PC that made the request. All the code I keep finding is how
to
get a WS to read a cookie, I need it to create one. The below code doesnt
add
the cookie to my cache. However if I place this in an non asmx page its
fine
>
Any help you offer is apperiated
>
[WebMethod(EnableSession=true)]
public string CreateToken(string User, string App, string County)
{
//Do some stuff
...
...
>
HttpCookie myCookie = new HttpCookie("NameMaster");
myCookie.Domain = "mydomain.com";
myCookie["ID"] = Result.ToString();
myCookie["User"] = User;
myCookie["App"] = App;
myCookie["County"] = County;
myCookie.Expires = DateTime.Now.AddMinutes(30);
HttpContext.Current.Response.Cookies.Add(myCookie) ; //doesnt work
--
JP
.NET Software Developer

Scott M.
Guest
 
Posts: n/a
#8: Feb 28 '07

re: How to get a WS to create a cookie???


Correction:

The code to create the
Quote:
cookie should be in the page/code that calls the *service*.
"Scott M." <s-mar@nospam.nospamwrote in message
news:OrygturWHHA.1180@TK2MSFTNGP05.phx.gbl...
Quote:
Cookies are created by the client (browser). As such, it wouldn't make
any sense for a web service to attempt to create a cookie because it is
one step removed from the correct source for cookies, the web server.
>
Client ---web page --a web service
>
See how the service is not the right place for this. The code to create
the cookie should be in the page/code that calls the cookie.
>
>
"JP" <JP@discussions.microsoft.comwrote in message
news:7713F4F9-7A6C-43F9-BA6D-39981234BABE@microsoft.com...
Quote:
>>I need to design a WS that will after authenicating the user, create a
>>cookie
>on the users PC that made the request. All the code I keep finding is how
>to
>get a WS to read a cookie, I need it to create one. The below code doesnt
>add
>the cookie to my cache. However if I place this in an non asmx page its
>fine
>>
>Any help you offer is apperiated
>>
>[WebMethod(EnableSession=true)]
>public string CreateToken(string User, string App, string County)
> {
>//Do some stuff
>...
>...
>>
>HttpCookie myCookie = new HttpCookie("NameMaster");
>myCookie.Domain = "mydomain.com";
>myCookie["ID"] = Result.ToString();
>myCookie["User"] = User;
>myCookie["App"] = App;
>myCookie["County"] = County;
>myCookie.Expires = DateTime.Now.AddMinutes(30);
>HttpContext.Current.Response.Cookies.Add(myCookie ); //doesnt work
>--
>JP
>.NET Software Developer
>
>

Closed Thread