服务器端:  
  public class BlogService:System.MarshalByRefObject
    { 
     public int GetArticleNums()
       {
          return (new DbDriver()).DriveLWordTask().GetArticleNums();
        //这行是执行数据库操作的.
       }
....
...  
        public string strRemoting()
        {
            return "This is from remote method";
        }    }
客户端:           RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile,false);
            BlogService bs= new BlogService();
            Console.WriteLine("Remoting Connected!");
            Console.WriteLine(bs.strRemoting());     //这行正确调用了服务器方法    
            Console.WriteLine("There is "+GetArticleNums()+"articles!");
//这行执行数据库操作时报错.具体错误:的类型初始值设定项引发异常。可能表述的不清楚,不好怎么表达了.晕.

解决方案 »

  1.   

    我用的是IIS做服务器端,客户端是个控制台DEMO.99吧
      

  2.   

    GetArticleNums(),你这个错误,这个是什么。。也不写出来单步调试,。看引发错误的语句
      

  3.   

    应该是 new DbDriver()).DriveLWordTask().GetArticleNums(); 出错的
    单步跟下就知道了
      

  4.   

    不是那个类其他问题,因为不做Remoting时,是正常的.
    执行数据库操作时报错.
    具体错误:GetData getdata=new GetData()(这是数据库操作类.我用它提取DATASET或DATAREADER的)类型初始值设定项引发异常。
    是不是序列化的问题,那么多类. 我在涉及未涉及的到类都加了[Serializable]郁闷,问题不好描述.
      

  5.   

    string IPstr = "";
                string filePath = Application.StartupPath + "\\IP.ini";
                IniFile dbini = new IniFile(filePath);
                IPstr = dbini.IniReadValue("IP", "ip") + dbini.IniReadValue("PORT", "port");
                IPstr = IPstr + "/BroadCastMessage.soap";
               
                BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
                BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
                serverProvider.TypeFilterLevel = TypeFilterLevel.Full;            IDictionary props = new Hashtable();
                props["port"] = 0;
                props["name"] = "ClientHttp";
                HttpChannel channel = new HttpChannel(props, clientProvider, serverProvider);
                ChannelServices.RegisterChannel(channel, false);
                return IPstr;
      

  6.   

    有些白痴我,想歪了
    客户端:
         RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile,false);
                BlogService bs = new BlogService();  //断点设这.
              //  BlogManageService bms = new BlogManageService();            Console.WriteLine("Remoting Connected!");
    我断点发现bs压根不是远程代理类.
    再看
    消息        1        未能找到元素“application”的架构信息。        
    消息        2        未能找到元素“client”的架构信息。        
    ....应当是他没有找到客户端配置信息,
    我不明为什么
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.runtime.remoting>
        <application>
          <client url="http://localhost/solog">
          <wellknown mode="Singleton" type="Solog.InterService.BlogService,InterService" url="http://localhost/solog/SologService.soap" />
          </client>
        </application>  </system.runtime.remoting>
    </configuration>
    找不到app.config这个配置信息.
      

  7.   

    我也不是很明白刚刚学
    http://www.cnblogs.com/wayfarer/category/1235.html
    看看这个网页很好的有例子