M
moondaddy
I had to repost this because I had to update and change my msdn alias. I
will re-ask the question and clarify a few things that were not clear
before.
This code is all executed on my dev machine running winXP sp2 and VS2005.
I'm using a c# 2.0 winforms app which talks to a c#2.0 asp.net app that also
contains 1 web service. Note: the webpage and web service are located side
by side in the same web app.
Scenario: the winform needs to call up a web page that has confidential
data that only the person logged into the winform is allowed to see. I
don't want to force the user to log into the win app and then log into the
web app too. so what I do is:
1) the winform calls a web service which generates a GUID and puts it into
server side cache for about 10 seconds (2 min while I'm testing and
debugging). the web service also caches the User ID and some other data
passed in from the winform.
2) the web service returns the GUID back to the winform via the WS return
value.
3) the winform calls the aspx page and passes the GUID in the url as a
parameter
4) the aspx page uses the GUID param as a key to find the cached data from
the related WS call.
5) if the cache is not found (call took too long or someone is
inappropriately call the page), its redirected to a page describing the
problem.
6) if the cache is found, the aspx page creates a serve side session object
to contain the User ID and other related data and the page is then returned
to the winform user.
This works great in a vb.net 1.1 app I have. I created this new c# 2.0 app
and used all the same code converted from vb.net 1.1 to c#2.0 but the aspx
page can not find the cached object. when I look in the HttpRuntime.Cache,
the item count is zero. However, to test this and make sure the code works
OK, I created a test aspx page which calls the web service and returns the
GUID. then I click on a 2nd button in the test page and it calls the
correct page passing in the GUID as a param just as the winform does and it
will find the cached object. all the code runs fine, its just that when
called from the winform, the cache cant be found. its like the WS called
from the winform is running in a different app from the web page called from
the same winform (although the aspx and asmx pages are both part of the same
app).
Here's my code:
I have a winforms 2.0 app that calls a web service which caches a GUID for a
short time like this:
[WebMethod(Description = "Get ticket for web page"),
SoapHeader("Credentials")]
public string GetWebPageTicket(string CurrentObject)
{
Guid CacheID = Guid.NewGuid();
SessionData obj = new SessionData();
obj.UserID = 1;// _credentials.UserID;
obj.CurrentObject = CurrentObject;
HttpRuntime.Cache.Insert(CacheID.ToString(), obj, null,
DateTime.Now.AddMinutes(2), System.Web.Caching.Cache.NoSlidingExpiration);
//HttpRuntime.Cache.Add(CacheID.ToString(), obj, null,
DateTime.Now.AddSeconds(60), TimeSpan.Zero,
System.Web.Caching.CacheItemPriority.Default, null);
return CacheID.ToString();
}
This web service returns the GUID back to the client where the client then
calls a aspx page and passes the GUID in as a parameter like this:
private void button1_Click(object sender, EventArgs e)
{
eVIPNow.eVIPNow_Gen_DAL obj = new eVIPNow.eVIPNow_Gen_DAL();
// GetWebPageTicket calls the WS and returns the GUID
string str = obj.GetWebPageTicket("xyz");
string url = ConfigurationManager.AppSettings["HelpPath"] +
"app/SuggestionLog.aspx?Param=" + str;
// This is where we call the aspx page
System.Diagnostics.Process.Start(url);
}
Now in the aspx page I run this code in and effort to find the cached GUID
from the WS:
// See if we can find the param in our cache
_sessionData = (SessionData)HttpRuntime.Cache[param];
where param is the GUID string value. this code returns null and
HttpRuntime.Cache has zero items in it. its almost like the WS and aspx
page are hitting 2 different instances of IIS.
I have very similar code running in another app which uses vb 1.1 and it
works good.
Any ideas why this doesn't work?
Thanks.
will re-ask the question and clarify a few things that were not clear
before.
This code is all executed on my dev machine running winXP sp2 and VS2005.
I'm using a c# 2.0 winforms app which talks to a c#2.0 asp.net app that also
contains 1 web service. Note: the webpage and web service are located side
by side in the same web app.
Scenario: the winform needs to call up a web page that has confidential
data that only the person logged into the winform is allowed to see. I
don't want to force the user to log into the win app and then log into the
web app too. so what I do is:
1) the winform calls a web service which generates a GUID and puts it into
server side cache for about 10 seconds (2 min while I'm testing and
debugging). the web service also caches the User ID and some other data
passed in from the winform.
2) the web service returns the GUID back to the winform via the WS return
value.
3) the winform calls the aspx page and passes the GUID in the url as a
parameter
4) the aspx page uses the GUID param as a key to find the cached data from
the related WS call.
5) if the cache is not found (call took too long or someone is
inappropriately call the page), its redirected to a page describing the
problem.
6) if the cache is found, the aspx page creates a serve side session object
to contain the User ID and other related data and the page is then returned
to the winform user.
This works great in a vb.net 1.1 app I have. I created this new c# 2.0 app
and used all the same code converted from vb.net 1.1 to c#2.0 but the aspx
page can not find the cached object. when I look in the HttpRuntime.Cache,
the item count is zero. However, to test this and make sure the code works
OK, I created a test aspx page which calls the web service and returns the
GUID. then I click on a 2nd button in the test page and it calls the
correct page passing in the GUID as a param just as the winform does and it
will find the cached object. all the code runs fine, its just that when
called from the winform, the cache cant be found. its like the WS called
from the winform is running in a different app from the web page called from
the same winform (although the aspx and asmx pages are both part of the same
app).
Here's my code:
I have a winforms 2.0 app that calls a web service which caches a GUID for a
short time like this:
[WebMethod(Description = "Get ticket for web page"),
SoapHeader("Credentials")]
public string GetWebPageTicket(string CurrentObject)
{
Guid CacheID = Guid.NewGuid();
SessionData obj = new SessionData();
obj.UserID = 1;// _credentials.UserID;
obj.CurrentObject = CurrentObject;
HttpRuntime.Cache.Insert(CacheID.ToString(), obj, null,
DateTime.Now.AddMinutes(2), System.Web.Caching.Cache.NoSlidingExpiration);
//HttpRuntime.Cache.Add(CacheID.ToString(), obj, null,
DateTime.Now.AddSeconds(60), TimeSpan.Zero,
System.Web.Caching.CacheItemPriority.Default, null);
return CacheID.ToString();
}
This web service returns the GUID back to the client where the client then
calls a aspx page and passes the GUID in as a parameter like this:
private void button1_Click(object sender, EventArgs e)
{
eVIPNow.eVIPNow_Gen_DAL obj = new eVIPNow.eVIPNow_Gen_DAL();
// GetWebPageTicket calls the WS and returns the GUID
string str = obj.GetWebPageTicket("xyz");
string url = ConfigurationManager.AppSettings["HelpPath"] +
"app/SuggestionLog.aspx?Param=" + str;
// This is where we call the aspx page
System.Diagnostics.Process.Start(url);
}
Now in the aspx page I run this code in and effort to find the cached GUID
from the WS:
// See if we can find the param in our cache
_sessionData = (SessionData)HttpRuntime.Cache[param];
where param is the GUID string value. this code returns null and
HttpRuntime.Cache has zero items in it. its almost like the WS and aspx
page are hitting 2 different instances of IIS.
I have very similar code running in another app which uses vb 1.1 and it
works good.
Any ideas why this doesn't work?
Thanks.