另外,我试了不放到GAC中,还是不行 因为它并没将BIN目录作为探测的路径需要在另行指定才行 可是SAMPLE里面并没这个步骤哦而且对于建立虚拟目录,我用的时候如果不把它设为public web site就会报错:401无访问权限 是这样解决么?
还是两次调用的问题:如果我将B->C的调用由Singleton改成SingleCall,上述两种运行情况均可正常运行以下是部分相关的实验代码,请批评指教究竟那里处理出了问题。 应用程序A部分代码: static void Main() { RemotingConfiguration.Configure("c:\\MyPizza\\test.exe.config"); Application.Run(new Form1()); } private void button1_Click(object sender, System.EventArgs e) { ProductData ds=new ProductData(); using (ProductSystem ps = new ProductSystem()) { ds=ps.GetCategoryItems(1) ; dataGrid1.DataSource =ds.Tables[0]; }组件B部分代码:——————————————————————————————————————— public class ProductSystem : MarshalByRefObject,IDisposable { public ProductSystem() { RemotingConfiguration.Configure ("c:\\MyPizza\\MyPizza.BusinessFacade.dll.config"); } public ProductData GetCategoryItems(int categoryId) { using (Products productDataAccess = new Products()) { return productDataAccess.GetProductsByCategoryId(categoryId); } }
}
组件C部分代码:———————————————————————————————————— public class Products :MarshalByRefObject, IDisposable {
private SqlDataAdapter dsCommand;
public Products() {
dsCommand = new SqlDataAdapter();
dsCommand.SelectCommand = new SqlCommand(); dsCommand.SelectCommand.Connection = new SqlConnection("server=localhost; User Id=sa;Password=******;database=MyPizza"); dsCommand.TableMappings.Add("Table", ProductData.PRODUCT_TABLE); }
看中文真头疼!!!用iis放dll ; sdk有相应的sample的,我也做过,没问题!
这样做debug非常麻烦!在 dll 未完善之前,修改一点 就要改很多地方,容易出错。
如果时说Asp.NET应用的话,你的Asp.NET相应的web.config文件也要改,remoting是在client和server上都需要配置的。
我看SAMPLE的时候是择其一
自己做的时候不做那个都不行
是这样么??
你是做的是附带的sample吗,还是自己照sample写的?我是只放在bin目录下的!
我就是直接粘的代码,编译的啊
如果不放GAC会说找不到的啊
奇怪
我再试试。。
另有个问题请帮帮我:
情况是这样的:应用程序A,dll组件B和C
A采用远程调用B,B采用远程调用C两个远程调用采用HTTP信道,在IIS中承载,在配置文件中注册信道等
应用程序A在main中调用配置文件
组件B在构造子中调用配置文件远程调用的类均为服务器端激活且采用singleton
配置文件未做与生存期等相关设置
————————————————————
第一次运行成功
第二次报错:无法访问组件C中已处置的对象问题在那里呢?如何解决
A->B->C 返回给B->A ,A不结束就再调用 B->C
还是A完全结束了,再运行A?我也有个问题:虽然是用IIS来承载,但那个channel的类型 也可以设置为 tcp 的。但这样到底有没有用(tcp is faster)?因为dll是放在http的虚拟目录下的!
windows service可不可以做listener?
A->B->C C返回给B->A
此时:
A不结束再调用B->C,报C中的错
A结束再运行A,仍然报C中错
均说C中的类已经处置
是不是我资源释放的问题,还是???
tcp也能用么?我没试过哦,看MSDN说IIS承载时只能用HTTP的
我试试看
多谢你了~
因为它并没将BIN目录作为探测的路径需要在另行指定才行
可是SAMPLE里面并没这个步骤哦而且对于建立虚拟目录,我用的时候如果不把它设为public web site就会报错:401无访问权限
是这样解决么?
应用程序A部分代码:
static void Main()
{
RemotingConfiguration.Configure("c:\\MyPizza\\test.exe.config");
Application.Run(new Form1());
} private void button1_Click(object sender, System.EventArgs e)
{ ProductData ds=new ProductData();
using (ProductSystem ps = new ProductSystem())
{
ds=ps.GetCategoryItems(1) ;
dataGrid1.DataSource =ds.Tables[0];
}组件B部分代码:———————————————————————————————————————
public class ProductSystem : MarshalByRefObject,IDisposable {
public ProductSystem()
{
RemotingConfiguration.Configure ("c:\\MyPizza\\MyPizza.BusinessFacade.dll.config");
} public ProductData GetCategoryItems(int categoryId)
{
using (Products productDataAccess = new Products())
{
return productDataAccess.GetProductsByCategoryId(categoryId);
}
}
}
组件C部分代码:———————————————————————————————————— public class Products :MarshalByRefObject, IDisposable
{
private SqlDataAdapter dsCommand;
public Products()
{
dsCommand = new SqlDataAdapter();
dsCommand.SelectCommand = new SqlCommand();
dsCommand.SelectCommand.Connection = new SqlConnection("server=localhost; User Id=sa;Password=******;database=MyPizza"); dsCommand.TableMappings.Add("Table", ProductData.PRODUCT_TABLE);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(true);
}
protected virtual void Dispose(bool disposing)
{
if (! disposing)
return; // 由系统垃圾回收器管理
if (dsCommand != null )
{
if (dsCommand.SelectCommand != null)
{
if( dsCommand.SelectCommand.Connection != null)
dsCommand.SelectCommand.Connection.Dispose();
dsCommand.SelectCommand.Dispose();
}
dsCommand.Dispose();
dsCommand = null;
}
}
/// <summary>
/// 检索某一分类下所有的产品。
/// <param name="categoryId">被检索分类的分类编号。</param>
/// <retvalue>ProductData,包含产品简单信息的数据集。</retvalue>
/// </summary>
public ProductData GetProductsByCategoryId(int categoryId)
{
return FillProductData("从分类获得产品信息", "@分类编号", categoryId.ToString());
} private ProductData FillProductData(String commandText, String paramName, String paramValue)
{
if (dsCommand == null )
{
throw new System.ObjectDisposedException( GetType().FullName );
}
ProductData data = new ProductData(); SqlCommand command = dsCommand.SelectCommand;
command.CommandText = commandText;
command.CommandType = CommandType.StoredProcedure;
//为sql命令提供参数
SqlParameter param = new SqlParameter(paramName, SqlDbType.NVarChar, 255);
param.Value = paramValue;
command.Parameters.Add(param); dsCommand.Fill(data);
return data;
}
}