翻遍了google 都没有找到答案, 大家来看看这个remoting的问题。。 100分啊, 不够再加
二级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的构造函数中注册了。。