二级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的构造函数中注册了。。

解决方案 »

  1.   

    这么长的内容没有耐心看完, 为什么搞两级remoting?  感觉有点怪如果说是要放在Internet上,为什么不用 WebService + Remoting?
      

  2.   

    不要总想着用一种方法WebService + Remoting不是可以吗?
      

  3.   

    程序在局域网运行没有问题
    放到internet上就报错了,  MBV的InsertAndSelect()  报不能连接到远程服务器。。
    ===========================================================================
    你要查看你对外的端口
    http://218.104.153.43:1010/hello/MyObject.soap
    1010是否已经打开,如果没对internat开放,你又怎么可能访问到呢!
      

  4.   

    说明一下,,   系统设计时失误,如果不用二级remoting改动会很大; 1010端口也开放了。另外放开系统设计不说, 大家就技术上讨论讨论上面这样到底错误出现在哪里
    csdn上面好像也很少有remoting方面的文章, 郁闷~~~~
      

  5.   

    没人对remoting 感兴趣吗?/  自己顶一下。。
      

  6.   

    我只知道GOOGLE不到就BAIDU........
      

  7.   

    呵呵  其实baidu 也没有放过~~~~
      

  8.   

    放在两天了 , 居然连一点实质性的建议都没有。   csdn的高手们呢??
      

  9.   

    xuexi
    专家建议,还是不要轻易使用romoting!
      

  10.   

    局域网没问题,说明程序没问题。
    肯定是环境问题,按顺序检查原因:
    对外的端口是否开放
    防火墙(客户端,服务器端)有没有拦截
    IIS的设置,比如有没有限定IP
    IIS中的.net和客户端的版本是否一致
    仔细检查web.config
      

  11.   

    谢谢。OK送一份
     [email protected]
      

  12.   

    呵呵   今天下午终于搞定了。。   在一个e文网站上找到了结果。 还是被楼上那位兄弟说中了。
      看来国内真的很少有用remoting做项目的啊, 一个很实际的问题,如果你remoting,应该都会碰到。
      顺便散分。。