客户端远程调用服务器上的函数,客户端的代码中这样写的:
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通信。请大家赐教,帮帮忙啊
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通信。请大家赐教,帮帮忙啊
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);
}