|
List Info
Thread: C-Sharp (C#) Group: callcontext can run well in windows, but cannot in asp, why? thanks a lot
|
|
| C-Sharp (C#) Group: callcontext can run
well in windows, but cannot in asp, why?
thanks a lot |

|
2006-08-16 10:44:13 |
Dear all:
Can any expert help me? urgently?
I build a server class, with "CallContext"
remoting method, I can run
my client.exe in windows successfully, but I cannot run it
in asp.net
from webBrowser IE6.0( where I also defined a class almost
same as
client.exe, except all the program code is not in main()
method, but in
a public method which is not static),
my code is as follows:
spService.cs(to build spService.dll)
using System;
using System.Collections;
using System.Diagnostics;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting.Contexts;
using System.Runtime.Remoting.Channels;
using System.Security.Principal;
using System.Security.Permissions;
using System.Web;
using System.Web.Configuration;
namespace sp
{
namespace common
{
public class ContextBoundType : MarshalByRefObject
{
private DateTime starttime;
public ContextBoundType()
{
Console.WriteLine("A ContextBoundType
instance has been
created.");
starttime = DateTime.Now;
}
~ContextBoundType()
{
Console.WriteLine("ContextBoundType
being collected
after " + (new TimeSpan(DateTime.Now.Ticks -
starttime.Ticks)).ToString() + " seconds.");
}
public DateTime GetServerTime()
{
Console.WriteLine("Time requested by a
client.");
// This call overwrites the client's
// CallContextString.
//
CallContext.SetData("ServerThreadData", new
sendData("This is the server side
replacement."));
return DateTime.Now;
}
public bool closeServer(bool closeFlag)
{
if (closeFlag)
{
for (int i = 0; i < 1000; i++)
GC.Collect(i);
}
return (true);
}
//[PermissionSet(SecurityAction.LinkDemand)]
public System.Data.DataSet SetDataSource(string
ec,string
SqlTxt)
{
Console.WriteLine("DB requested by a
client.");
CallContext.SetData(ec, new
spDataTransfer(ec.Trim() +
"DS"));
spDataTransfer ds =
(spDataTransfer)(CallContext.GetData(ec));
//ds.SQL = SqlTxt;
Console.WriteLine("db after requested
by a client : " +
ds.spDataSource.DataSetName);
return (ds.spDataSource);
}
}
// One method of communicating between client and
server is
// to use the CallContext. Calling CallContext
essentially
puts the data
// in a Thread Local Store. This means that the
information is
available
// to that thread or that "logical"
thread (across application
domains) only.
[Serializable]
public class spDataTransfer :
ILogicalThreadAffinative
{
String _str = "";
string _PsId = "";
string _SQL = "";
public string PsId
{
get
{
return (_PsId);
}
set
{
_PsId = value;
}
}
public string SQL
{
get
{
return (_SQL);
}
set
{
_SQL = value;
}
}
//System.Data.DataSet DataSource;
public spDataTransfer(String str)
{
_str = str;
this.PsId = str;
//Console.WriteLine("CallContextString
created.");
}
public override String ToString()
{
string GlbDBstring =
WebConfigurationManager.AppSettings["GlobalDB"].
ToString();
return GlbDBstring;
}
public System.Data.DataSet spDataSource
{
get
{
return (getDataSource(PsId));
}
}
public System.Data.DataSet getDataSource(string
refId)
{
System.Data.DataSet newDs = new
System.Data.DataSet(refId);
System.Data.DataTable newDT = new
System.Data.DataTable();
newDT.Columns.Add(new
System.Data.DataColumn("T1",
System.Type.GetType("System.Int32")));
System.Data.DataRow dr = newDT.NewRow();
dr[0] = 32;
newDT.Rows.Add(dr);
newDs.Tables.Add(newDT);
return (newDs);
}
}
}
}
spServer.cs : (to build spserver.exe)
using System;
using System.Diagnostics;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Remoting.Contexts;
using System.Runtime.Remoting.Messaging;
using System.Threading;
namespace sp
{
namespace common
{
public class spServerProcess
{
public static void Main(string[] Args)
{
HttpChannel channel = new HttpChannel(8082);
ChannelServices.RegisterChannel(channel,
false);
WellKnownServiceTypeEntry WKSTE = new
WellKnownServiceTypeEntry(typeof(sp.common.ContextBoundType)
,
"HttpService", WellKnownObjectMode.Singleton);
//RemotingConfiguration.ApplicationName =
"HttpService";
//RemotingConfiguration.RegisterWellKnownServiceType(typeof(
sp.common.ContextBoundType),
"HttpService",WellKnownObjectMode.Singleton);
RemotingConfiguration.RegisterWellKnownServiceType(WKSTE);
Console.WriteLine("Press enter to stop
this process.");
Console.ReadLine();
}
}
}
}
Client.cs: ( to build client.exe)
using System;
using System.Reflection;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Remoting.Contexts;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting.Lifetime;
using System.Security.Permissions;
using System.Data;
using sp.common;
namespace sp
{
namespace webAsp
{
public class spClientProcess
{
// [SecurityPermission(SecurityAction.Demand)]
public static void Main(string[] Args)
{
string indId = "inited";
try
{
indId = "creatChanel";
HttpChannel channel = new
HttpChannel();
ChannelServices.RegisterChannel(channel,
false);
WellKnownClientTypeEntry remotetype
= new
WellKnownClientTypeEntry(typeof(sp.common.ContextBoundType),
"http://localhost:80
82/HttpService");
RemotingConfiguration.RegisterWellKnownClientType(remotetype
);
// This sets a CallContextDataSlot on
this thread.
// CallContextString will convert the
ThreadLocalDataStore into
// a property on the message, which will
then be
merged into the
// ThreadLocalDataStore on the server.
This is a
nice way to pass
// information from client to server
threads and
back again.
// NOTE: This data store has logical
thread scope.
If an
// application domain has more than one
thread
making calls,
// each thread will have its own logical
CallContext, and the
// server thread will keep each
separate.
/*
*
*
CallContext.SetData("ServerThreadData", new
CallContextString("This is the thread data inserted on
the client
thread."));
*
Console.WriteLine("CallContextString prior to
the call: " +
CallContext.GetData("ServerThreadData").ToString
());
* ContextBoundType service = new
ContextBoundType();
* Console.WriteLine("Server time
is: " +
service.GetServerTime().ToLongTimeString());
*
Console.WriteLine("CallContextString after the
call: " +
CallContext.GetData("ServerThreadData").ToString
());
* // create an instance on the
remote server
// and call a method remotely
Reverser rev =
(Reverser)Activator.GetObject(
typeof(Reverser),"http://localhost:
8000/Reverser.soap" );
*/
string cks = "Test";
if (cks == "")
cks = "Xa";
indId = "createds";
System.Data.DataSet ds = new DataSet();
spDataTransfer sd = new
spDataTransfer(cks);
indId =
"createcontextsetData";
CallContext.SetData(cks, sd);
indId =
"createdContxtGetData";
sd =
(spDataTransfer)(CallContext.GetData(cks));
indId = "createcontextType";
ContextBoundType service = new
ContextBoundType();
indId =
"createbyFuncCalling";
//string ias =
service.GetServerTime().Second.ToString();
ds =
service.SetDataSource(cks,"test");
indId =
"CallServiceSucceed";
ds = sd.spDataSource;
indId =
"runSPtransferSucced";
ds = sd.getDataSource(cks);
indId = "AllSucceed";
ds.DataSetName = indId;
Console.WriteLine("succeed!");
}
catch (Exception e)
{
Console.WriteLine(indId + e.Message);
}
//return (null);
}
}
}
}
spClient.cs ( to build spClient.dll, then I call it from
some other asp
page):
using System;
using System.Reflection;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Remoting.Contexts;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting.Lifetime;
using System.Security.Permissions;
using System.Data;
using sp.common;
namespace sp
{
namespace webAsp
{
public class spClientProcess
{
// [SecurityPermission(SecurityAction.Demand)]
public System.Data.DataSet getDataSource(string
refId)
{
string indId = "inited";
try
{
indId = "creatChanel";
try
{
HttpChannel channel = new
HttpChannel();
ChannelServices.RegisterChannel(channel,
false);
WellKnownClientTypeEntry
remotetype = new
WellKnownClientTypeEntry(typeof(sp.common.ContextBoundType),
"http://localhost:80
82/HttpService");
RemotingConfiguration.RegisterWellKnownClientType(remotetype
);
}
catch
{
}
// This sets a CallContextDataSlot
on this
thread.
// CallContextString will convert the
ThreadLocalDataStore into
// a property on the message, which will
then be
merged into the
// ThreadLocalDataStore on the server.
This is a
nice way to pass
// information from client to server
threads and
back again.
// NOTE: This data store has logical
thread scope.
If an
// application domain has more than one
thread
making calls,
// each thread will have its own logical
CallContext, and the
// server thread will keep each
separate.
/*
*
*
CallContext.SetData("ServerThreadData", new
CallContextString("This is the thread data inserted on
the client
thread."));
*
Console.WriteLine("CallContextString prior to
the call: " +
CallContext.GetData("ServerThreadData").ToString
());
* ContextBoundType service = new
ContextBoundType();
* Console.WriteLine("Server time
is: " +
service.GetServerTime().ToLongTimeString());
*
Console.WriteLine("CallContextString after the
call: " +
CallContext.GetData("ServerThreadData").ToString
());
* // create an instance on the
remote server
// and call a method remotely
Reverser rev =
(Reverser)Activator.GetObject(
typeof(Reverser),"http://localhost:
8000/Reverser.soap" );
*/
string cks = refId;
if (cks == "")
cks = "Xa";
indId = "createds";
System.Data.DataSet ds = new DataSet();
spDataTransfer sd = new
spDataTransfer(cks);
indId =
"createcontextsetData";
CallContext.SetData(cks, sd);
indId =
"createdContxtGetData";
sd =
(spDataTransfer)(CallContext.GetData(cks));
indId = "createcontextType";
ContextBoundType service = new
ContextBoundType();
indId =
"createbyFuncCalling";
//string ias =
service.GetServerTime().Second.ToString();
ds =
service.SetDataSource(cks,"test");
indId =
"CallServiceSucceed";
ds = sd.spDataSource;
indId =
"runSPtransferSucced";
ds = sd.getDataSource(cks);
indId = "AllSucceed";
ds.DataSetName = indId;
return (ds);
}
catch (Exception e)
{
string ss = e.Message;
System.Data.DataSet newDs = new
System.Data.DataSet(refId);
/*
System.Data.DataTable newDT = new
System.Data.DataTable();
newDT.Columns.Add(new
System.Data.DataColumn("T1",
System.Type.GetType("System.String")));
System.Data.DataRow dr = newDT.NewRow();
dr[0] = "except happened";
newDT.Rows.Add(dr);
newDs.Tables.Add(newDT);
*/
newDs.DataSetName = indId +
"_err";
return (newDs);
}
//return (null);
}
}
}
}
the code I call spClient.cs ( spClient.dll):
spPageBase.cs:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using sp.common;
namespace sp
{
namespace webAsp
{
/// <summary>
/// Summary description for spPageBase
/// </summary>
public class spPageBase : Page
{
private DataSet ds;
public DataSet spDataSource
{
get
{
return (ds);
}
set
{
ds = value;
this.DataBind();
}
}
public spFuncLib funcLib = new spFuncLib();
string s_id = "";
public string PsId
{
get
{
return (s_id);
}
set
{
string oldId = s_id;
s_id = value;
if (oldId != s_id)
{
try
{
this.reinitialize();
}
catch //(Exception e)
{
this.Response.Write(this.Title +
" has
error while initialization!" +
"<br>" + "Please correct error and
try
again!");
s_id = "";
}
}
}
}
public spPageBase()
{
//
// TODO: Add constructor logic here
//
}
protected void reinitialize()
{
//funcLib.initialize(this);
this.PsId = "Test";
spClientProcess newspClient = new
spClientProcess();
this.Title = "Before run get
DS";
//spClientProcess.getDataSource(this.PsId);
this.spDataSource =
newspClient.getDataSource(this.PsId);
//if (this.spDataSource == null)
// {
this.Title = this.spDataSource.DataSetName ;
// }
}
}
}
}
and the asp PAge(a Blank page only with some text and the
title)
Service.aspx.CS:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using sp.webAsp;
using sp.common;
public partial class Services : spPageBase
{
protected new void Page_Load(object sender, EventArgs e)
{
int i = 0;
this.reinitialize();
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharp googlegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribe googlegroups.com
For more options, visit this group at http://groups.
google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---
|
|
| C-Sharp (C#) Group: Re: callcontext can
run well in windows, but cannot in asp,
why? thanks a lot |

|
2006-08-16 11:30:24 |
|
<snip>
A good starting point is
http://www.codeproject.com/aspnet/ASPDontNetRemoting.asp. Without
knowing the exact exception that you are having generated it is
difficult to suggest how you can work around this problem but as with
most things asp.net & remoting related I suspect it will boil down
to a application trust (Remoting needs a FullTrust environment to
function correctly) or security (your code will be running in the
context of whichever user your Application Pool is set to use unless
otherwise specified unless you use impersonation to change it). If you
can tell us exactly the exception that gets generated we would be able
to help you more.
Liam
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "C-Sharp (C#)" group. To post to this group, send email to C_Sharp googlegroups.com To unsubscribe from this group, send email to C_Sharp-unsubscribe googlegroups.com For more options, visit this group at http://groups.google.com/group/C_Sharp -~----------~----~----~----~------~----~------~--~---
|
| C-Sharp (C#) Group: Re: callcontext can
run well in windows, but cannot in asp,
why? thanks a lot |

|
2006-08-16 12:08:10 |
the exception shows the : createbyFuncCalling_err.
for I use indId to trace, and the real exception message is:
e.Message = "Parse Error, no assembly associated with
Xml key
a2:http://schemas.microsoft.com/cl
r/nsassem/sp.common/App_Code.4yip1gl7%2C%20Version%3D0.0.0.0
%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull
spDataTransfer"
but the strange point is it can create the remote type.
Thankx.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharp googlegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribe googlegroups.com
For more options, visit this group at http://groups.
google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---
|
|
| C-Sharp (C#) Group: Re: callcontext can
run well in windows, but cannot in asp,
why? thanks a lot |

|
2006-08-16 13:08:58 |
hi,Dear expert:
After I went through your sample in codeproject, I cannot go
alive yet,
could you help me more, thanks a lot.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharp googlegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribe googlegroups.com
For more options, visit this group at http://groups.
google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---
|
|
| C-Sharp (C#) Group: Re: callcontext can
run well in windows, but cannot in asp,
why? thanks a lot |

|
2006-08-16 13:46:55 |
|
I will give it a run and see for myself when I get home but "no
assembly associated with Xml key" exceptions usually result from the
client not having the assembly that contains the remote type in their
bin directory (at work atm so don't have time to run through this
myself right now). Make sure the assembly your remote type exists in is
present in the bin directory. If that doesn't help maybe someone else
might be able to lend a hand, if not I will take a look at the problem
this evening.
Liam
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "C-Sharp (C#)" group. To post to this group, send email to C_Sharp googlegroups.com To unsubscribe from this group, send email to C_Sharp-unsubscribe googlegroups.com For more options, visit this group at http://groups.google.com/group/C_Sharp -~----------~----~----~----~------~----~------~--~---
|
| C-Sharp (C#) Group: Re: callcontext can
run well in windows, but cannot in asp,
why? thanks a lot |

|
2006-08-16 14:35:28 |
Hi,Expert, I use follows command line to compile the .CS
file, whether
it leads to error?
C:\WINNT\Microsoft.NET\Framework\v2.0.50727\csc
/r:System.Runtime.Remoting.dll;System.Data.dll;System.Web.dl
l
/t:library spService.cs
C:\WINNT\Microsoft.NET\Framework\v2.0.50727\csc
/r:System.Runtime.Remoting.dll;System.Data.dll;System.Web.dl
l
/r:spService.dll spServer.cs
C:\WINNT\Microsoft.NET\Framework\v2.0.50727\csc
/r:System.Runtime.Remoting.dll /r:spService.dll /t:library
spclient.cs
C:\WINNT\Microsoft.NET\Framework\v2.0.50727\csc
/r:System.Runtime.Remoting.dll /r:spService.dll client.cs
After compiled, if I run client.exe, all results are correct
and
running well, if I call from asp.net, then I can only run to
"indId":
"createbyFuncCalling". then stop, It cannot run
server functions.
Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharp googlegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribe googlegroups.com
For more options, visit this group at http://groups.
google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---
|
|
| C-Sharp (C#) Group: Re: callcontext can
run well in windows, but cannot in asp,
why? thanks a lot |

|
2006-08-16 14:51:57 |
I added all reference, but it doesnot work yet, it stays
same that
client.exe can connect and use server functions.
C:\WINNT\Microsoft.NET\Framework\v2.0.50727\csc
/r:System.Runtime.Remoting.dll;System.Security.dll;System.Da
ta.dll;System.Web.dll
/t:library spCommon.cs
C:\WINNT\Microsoft.NET\Framework\v2.0.50727\csc
/r:System.Runtime.Remoting.dll;System.Data.dll;System.Web.dl
l
/r:spCommon.dll /t:library spService.cs
C:\WINNT\Microsoft.NET\Framework\v2.0.50727\csc
/r:System.Runtime.Remoting.dll;System.Data.dll;System.Web.dl
l
/r:spService.dll spServer.cs
C:\WINNT\Microsoft.NET\Framework\v2.0.50727\csc
/r:System.Runtime.Remoting.dll;System.Security.dll;System.Da
ta.dll;System.Web.dll;F:\AISDocs\spWeb\App_Code\Common\
spService.dll;F:\AISDocs\spWeb\App_Code\Common\spCommon
.dll
/t:library spclient.cs
C:\WINNT\Microsoft.NET\Framework\v2.0.50727\csc
/r:System.Runtime.Remoting.dll;System.Security.dll;System.Da
ta.dll;System.Web.dll;F:\AISDocs\spWeb\App_Code\Common\
spService.dll;F:\AISDocs\spWeb\App_Code\Common\spCommon
.dll
client.cs
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharp googlegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribe googlegroups.com
For more options, visit this group at http://groups.
google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---
|
|
| C-Sharp (C#) Group: Re: callcontext can
run well in windows, but cannot in asp,
why? thanks a lot |

|
2006-08-17 15:13:07 |
hi,Liam Leane:
Could you give a little more help, very embarrassed but I
really
appreciate you for that.
the client.exe can run to the end successfully without any
error. the
web page can only run to "createbyFuncCalling",
it stops while it calls
the server function.
Thanks for your kindness.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharp googlegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribe googlegroups.com
For more options, visit this group at http://groups.
google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---
|
|
| C-Sharp (C#) Group: Re: callcontext can
run well in windows, but cannot in asp,
why? thanks a lot |

|
2006-08-17 19:26:45 |
|
Having a few puter problems that are preventing me from testing this on my puter but it looks very much like you just need to copy the assembly with the remoting type in to your web application bin folder. I hope that help with your problem, not much I can check with a dud computer
On 8/16/06,
seagullw <gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">seagullfei gmail.com> wrote:
I added all reference, but it doesnot work yet, it stays same that client.exe can connect and use server functions.
C:\WINNT\Microsoft.NET\Framework\v2.0.50727\csc /r:System.Runtime.Remoting.dll;System.Security.dll;System.Data.dll;System.Web.dll
/t:library spCommon.cs C:\WINNT\Microsoft.NET\Framework\v2.0.50727\csc /r:System.Runtime.Remoting.dll;System.Data.dll;System.Web.dll /r:spCommon.dll /t:library spService.cs C:\WINNT\Microsoft.NET\Framework\v2.0.50727\csc
/r:System.Runtime.Remoting.dll;System.Data.dll;System.Web.dll /r:spService.dll spServer.cs C:\WINNT\Microsoft.NET\Framework\v2.0.50727\csc /r:System.Runtime.Remoting.dll;System.Security.dll;System.Data.dll;System.Web.dll;F:\AISDocs\spWeb\App_Code\Common\spService.dll;F:\AISDocs\spWeb\App_Code\Common\spCommon.dll
/t:library spclient.cs C:\WINNT\Microsoft.NET\Framework\v2.0.50727\csc /r:System.Runtime.Remoting.dll;System.Security.dll;System.Data.dll;System.Web.dll;F:\AISDocs\spWeb\App_Code\Common\spService.dll;F:\AISDocs\spWeb\App_Code\Common\spCommon.dll
client.cs
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "C-Sharp (C#)" group. To post to this group, send email to C_Sharp googlegroups.com To unsubscribe from this group, send email to C_Sharp-unsubscribe googlegroups.com For more options, visit this group at http://groups.google.com/group/C_Sharp -~----------~----~----~----~------~----~------~--~---
|
[1-9]
|
|