二级remoting调用。。 iis承载的
MyObject是服务端激活对象, MBV是MyObject返回的客户端激活对象。。 程序在局域网运行没有问题
放到internet上就报错了, MBV的InsertAndSelect() 报不能连接到远程服务器。。
大家帮帮忙。。 大家也可以在 http://lovingni.googlepages.com/TestRemoting.rar 下载源码。服务端代码:
using System;
using System.Data.SqlClient;
using System.Data;
using System.Collections;
using System.Runtime.Remoting;using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Remoting.Activation;using log4net;namespace ShareAssembly
{ public class MyObject:MarshalByRefObject
{ public int i;
ILog log; public MyObject()
{
log4net.Config.XmlConfigurator.Configure();
log = LogManager.GetLogger( this.GetType() );
log.Info( "MyObject 构造函数" );
} public int Add(int a,int b)
{
log.Info( "Add前" );
return 10; } public MBV GetChildObject()
{
try
{
log.Info( "GetChildObject前" ); object []o = {new UrlAttribute("http://218.104.153.43:1010/hello/MBV")};
MBV b =
(MBV)Activator.CreateInstance( typeof(ShareAssembly.MBV) );
log.Info( "GetChildObject后" );
return b; }
catch(Exception err )
{
log.Info( "-----------", err );
throw err;
}
} } public class MBV : MarshalByRefObject
{
public DataTable dt;
ILog log; public MBV()
{
log = LogManager.GetLogger( this.GetType() );
log.Info( "MBV 构造函数" );
} public DataTable InsertAndSelect()
{
log.Info( "InsertAndSelect前" );
try
{
SqlConnection sqlConn = new SqlConnection( "server=10.1.1.100;database=pubs;uid=sa;pwd=1;" );
SqlCommand sqlCmd = new SqlCommand( "insert into jobs values('我的测试数据',101,101 )", sqlConn );
sqlConn.Open();
sqlCmd.ExecuteNonQuery();
sqlConn.Close(); SqlDataAdapter sqlDa = new SqlDataAdapter( "select * from jobs", sqlConn );
DataSet ds = new DataSet();
sqlDa.Fill( ds ); dt = ds.Tables[0]; log.Info( "InsertAndSelect后" );
return ds.Tables[0];
}
catch( Exception err )
{
log.Info( err ); return new DataTable();
}
}
}}web.config文件:
<application>
<service>
<wellknown mode="SingleCall" type="ShareAssembly.MyObject, ShareAssembly" objectUri="MyObject.soap"/>
<activated type="ShareAssembly.MBV,ShareAssembly" objectUri="MBV.soap"/>
</service>
<channels>
<channel ref="http" >
<serverProviders>
<provider ref="wsdl" metadataEnabled="true" remoteApplicationMetadataEnabled="true" />
<formatter ref="soap" typeFilterLevel="Full"/>
</serverProviders>
</channel>
</channels>
</application>
客户端代码:
private void button1_Click(object sender, System.EventArgs e)
{
try
{
MyObject mo = (MyObject) Activator.GetObject(
typeof(MyObject),"http://218.104.153.43:1010/hello/MyObject.soap");
int n = mo.Add( 10, 20 );
n= mo.i;
MessageBox.Show( n.ToString() + " 根对象的方法调用成功" );
MBV m =mo.GetChildObject();
MessageBox.Show( "获得二级对象" );
m.InsertAndSelect();
MessageBox.Show( "二级对象调用成功" );
this.dataGrid1.DataSource = m.dt;
}
catch( Exception err )
{
MessageBox.Show( "出错了:\n" + err.ToString() );
}
}
客户端通道在Form1的构造函数中注册了。。
MyObject是服务端激活对象, MBV是MyObject返回的客户端激活对象。。 程序在局域网运行没有问题
放到internet上就报错了, MBV的InsertAndSelect() 报不能连接到远程服务器。。
大家帮帮忙。。 大家也可以在 http://lovingni.googlepages.com/TestRemoting.rar 下载源码。服务端代码:
using System;
using System.Data.SqlClient;
using System.Data;
using System.Collections;
using System.Runtime.Remoting;using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Remoting.Activation;using log4net;namespace ShareAssembly
{ public class MyObject:MarshalByRefObject
{ public int i;
ILog log; public MyObject()
{
log4net.Config.XmlConfigurator.Configure();
log = LogManager.GetLogger( this.GetType() );
log.Info( "MyObject 构造函数" );
} public int Add(int a,int b)
{
log.Info( "Add前" );
return 10; } public MBV GetChildObject()
{
try
{
log.Info( "GetChildObject前" ); object []o = {new UrlAttribute("http://218.104.153.43:1010/hello/MBV")};
MBV b =
(MBV)Activator.CreateInstance( typeof(ShareAssembly.MBV) );
log.Info( "GetChildObject后" );
return b; }
catch(Exception err )
{
log.Info( "-----------", err );
throw err;
}
} } public class MBV : MarshalByRefObject
{
public DataTable dt;
ILog log; public MBV()
{
log = LogManager.GetLogger( this.GetType() );
log.Info( "MBV 构造函数" );
} public DataTable InsertAndSelect()
{
log.Info( "InsertAndSelect前" );
try
{
SqlConnection sqlConn = new SqlConnection( "server=10.1.1.100;database=pubs;uid=sa;pwd=1;" );
SqlCommand sqlCmd = new SqlCommand( "insert into jobs values('我的测试数据',101,101 )", sqlConn );
sqlConn.Open();
sqlCmd.ExecuteNonQuery();
sqlConn.Close(); SqlDataAdapter sqlDa = new SqlDataAdapter( "select * from jobs", sqlConn );
DataSet ds = new DataSet();
sqlDa.Fill( ds ); dt = ds.Tables[0]; log.Info( "InsertAndSelect后" );
return ds.Tables[0];
}
catch( Exception err )
{
log.Info( err ); return new DataTable();
}
}
}}web.config文件:
<application>
<service>
<wellknown mode="SingleCall" type="ShareAssembly.MyObject, ShareAssembly" objectUri="MyObject.soap"/>
<activated type="ShareAssembly.MBV,ShareAssembly" objectUri="MBV.soap"/>
</service>
<channels>
<channel ref="http" >
<serverProviders>
<provider ref="wsdl" metadataEnabled="true" remoteApplicationMetadataEnabled="true" />
<formatter ref="soap" typeFilterLevel="Full"/>
</serverProviders>
</channel>
</channels>
</application>
客户端代码:
private void button1_Click(object sender, System.EventArgs e)
{
try
{
MyObject mo = (MyObject) Activator.GetObject(
typeof(MyObject),"http://218.104.153.43:1010/hello/MyObject.soap");
int n = mo.Add( 10, 20 );
n= mo.i;
MessageBox.Show( n.ToString() + " 根对象的方法调用成功" );
MBV m =mo.GetChildObject();
MessageBox.Show( "获得二级对象" );
m.InsertAndSelect();
MessageBox.Show( "二级对象调用成功" );
this.dataGrid1.DataSource = m.dt;
}
catch( Exception err )
{
MessageBox.Show( "出错了:\n" + err.ToString() );
}
}
客户端通道在Form1的构造函数中注册了。。
放到internet上就报错了, MBV的InsertAndSelect() 报不能连接到远程服务器。。
===========================================================================
你要查看你对外的端口
http://218.104.153.43:1010/hello/MyObject.soap
1010是否已经打开,如果没对internat开放,你又怎么可能访问到呢!
csdn上面好像也很少有remoting方面的文章, 郁闷~~~~
专家建议,还是不要轻易使用romoting!
肯定是环境问题,按顺序检查原因:
对外的端口是否开放
防火墙(客户端,服务器端)有没有拦截
IIS的设置,比如有没有限定IP
IIS中的.net和客户端的版本是否一致
仔细检查web.config
[email protected]
看来国内真的很少有用remoting做项目的啊, 一个很实际的问题,如果你remoting,应该都会碰到。
顺便散分。。