客户端远程调用服务器上的函数,客户端的代码中这样写的:
 IDisp proxy = (IDisp)Activator.GetObject(typeof(IDis), "http://localhost:8083/Myserver/ss.soap");
其中,IDisp 是服务端的一个接口。运行到这里就报错,第一个错误是“"System.ArgumentNullException: No message was deserialized prior to calling the DispatchChannelSink. Parameter name: requestMsg”,GOOGLE一下,说有可能是服务端的channel与客户端的channel的formatter不对造成的,于是就修改了服务端的formatter为“soap”,再次运行这个错误不出现了,可是出现了另外一个异常:“Remoting cannot find field '__identity' on type 'System.MarshalByRefObject',   System.Runtime.Remoting.RemotingException: Permission denied: cannot call non-public or static methods remotely.”。可是接口IDisp中并没有静态方法啊,GOOGLE了一下也没有找到结果。我用的是http通信。请大家赐教,帮帮忙啊

解决方案 »

  1.   

    不清楚你的是什么问题,不过可以给你一个实例参考参考~有些参数你可能不需要~server
    from_load事件
    RemotingConfiguration.Configure("RemoteServer.exe.config");RemoteServer.exe.config
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.runtime.remoting>
        <application name="RemoteServer">
          <service>
            <wellknown type="RemoteObject.MyObject,RemoteObject" objectUri="RemoteObject.MyObject"
                mode="Singleton" />
          </service>
          <channels>
            <channel ref="tcp" port="9999"/>
          </channels>
        </application>
      </system.runtime.remoting>
    </configuration>Client
    from初始化
            //无接口
            //RemoteObject.MyObject app = (RemoteObject.MyObject)Activator.GetObject(typeof(RemoteObject.MyObject), System.Configuration.ConfigurationSettings.AppSettings["ServiceURL"]);
            
            //有接口
            RemoteObject.IMyObject app = (RemoteObject.IMyObject)Activator.GetObject(typeof(RemoteObject.IMyObject), System.Configuration.ConfigurationSettings.AppSettings["ServiceURL"]);Client.exe.config
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
          <section name="RemoteClient.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
      </configSections>
      <appSettings>
        <add key="ServiceURL" value="tcp://127.0.0.1:9999/RemoteObject.MyObject" />
        <add key="ClientSettingsProvider.ServiceUri" value="" />
      </appSettings>
      <applicationSettings>
        <RemoteClient.Properties.Settings>
          <setting name="BuffSize" serializeAs="String">
            <value>1000000</value>
          </setting>
          <setting name="SleepTime" serializeAs="String">
            <value>100</value>
          </setting>
        </RemoteClient.Properties.Settings>
      </applicationSettings>
    </configuration>接口
    public interface IMyObject //接口
        {
            //DataSet GetDataSet(string sql);
            //int ExecuteSql(string sql);
            //byte[] SendFile(string fileName);
            byte[] ReadFile(string fileName, int wz, int bb);
            void DeleteFile(string filename);
            int ReturnLength(string fileName);
            void writefiles(string filepatch, string filename, int i, byte[] b);
        }
      

  2.   

    具体怎么解决现在有点忘记了,不过要保证2点,第一是:确保客户端与服务端所配置的通道的各个参数一致,相匹配;第二是,所要传的类一定要继承于MARSHALLOBJECT(就是那个接口,忘记了~~)。我当时就是因为第二点没有满足,所要传的类可能与别的类有一定关系,那么也要确保相关的类继承于MARSHALLOBJECT.或着确保可序列化