首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

Remoting 调用远程sington对象的方法抛出错误

2012-06-19 
Remoting 调用远程sington对象的方法抛出异常程序有三个模块组成,一个公共模块dll,定义远程对象,及一些参

Remoting 调用远程sington对象的方法抛出异常
程序有三个模块组成,
一个公共模块dll,定义远程对象,及一些参数类
一个客户端exe,调用服务器端的远程sington对象的方法,传递可序列话的参数
一个服务器exe,提供客户端访问的远程sington对象

问题:在客户端调用方法时,服务器抛出异常,异常信息调用堆栈显示,是服务器获取客户端传输的参数时超时,请高手分析什么问题。

测试环境1:客户端在win7系统的电脑A,服务器在xp系统的电脑B,出现以上描述问题
测试环境2:同样的程序,客户端运行在xp,服务器运行在win7时,结果正常。

代码:

///公共模块
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace eocDemoCommon
{
  public class ServerImpl : MarshalByRefObject, IServer
  {
  public bool CallFun(ClientParam para)
  {
  Console.WriteLine(para.User + para.Pwd);
  return true;
  }
  }
  public interface IServer
  {
  bool CallFun(ClientParam para);
  }

  [System.SerializableAttribute()]
  public class ClientParam : MarshalByRefObject
  {
  private string _user;
  private string _pwd;
  public string User{
  get { return _user; }
  set { _user = value; }
  }
  public string Pwd
  {
  get { return _pwd; }
  set { _pwd = value; }
  }

  }
}
///客户端

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting;
using eocDemoCommon;

namespace eocDemoClient
{
  class Program
  {
  static void Main(string[] args)
  {
  IServer service;
  string uri = "";
  RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, false);
  foreach (WellKnownClientTypeEntry clienttype in RemotingConfiguration.GetRegisteredWellKnownClientTypes())
  {
  Console.WriteLine(clienttype.ObjectUrl);
  uri = clienttype.ObjectUrl;
  break;
  }
  if (uri.Length >= 0)
  {
  service = (IServer)Activator.GetObject(typeof(IServer), uri);
  try
  {
  ClientParam parm = new ClientParam();
  parm.User = "hello ";
  parm.Pwd = "world";
  service.CallFun(parm);
  Console.ReadKey();
  }
  catch (Exception ex)
  {
  Console.WriteLine(ex.ToString());
  Console.ReadKey();
  }
  }
  }
  }
}


///服务器

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Remoting;

namespace eocDemoServer
{
  public partial class Form1 : Form
  {
  public Form1()
  {
  InitializeComponent();
  try
  {
  RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, false);
  }
  catch (Exception ex)
  {
  Console.WriteLine(ex.ToString());
  }
  }


  }
}

客户端配置文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.runtime.remoting>
  <application>
  <client>
  <wellknown type="eocDemoCommon.ServerImpl, eocDemoCommon" url="http://192.168.88.132:8190/eocDemoCommon.IServer" />
  </client>
  <channels>
  <channel ref="http" port="0">
  <serverProviders>
  <provider ref="wsdl" />
  <formatter ref="soap" typeFilterLevel="Full" />
  <formatter ref="binary" typeFilterLevel="Full" />
  </serverProviders>
  </channel>
  </channels>
  </application>
  </system.runtime.remoting>
</configuration>

///服务端配置文件
<?xml version="1.0"?>
<configuration>
  <system.runtime.remoting>
  <customErrors mode="off"/>
  <application>
  <service>
  <wellknown mode="Singleton" type="eocDemoCommon.ServerImpl, eocDemoCommon" objectUri="eocDemoCommon.IServer"/>
  </service>
  <channels>
  <channel port="8190" ref="http">
  <serverProviders>
  <provider ref="wsdl"/>
  <formatter ref="soap" typeFilterLevel="Full"/>
  <formatter ref="binary" typeFilterLevel="Full"/>
  </serverProviders>
  </channel>
  </channels>
  <!--leaseManagerPollTime="7S"
  <lifetime leaseTime="70M" sponsorshipTimeout="70M" renewOnCallTime="70M"/>-->
  </application>
  </system.runtime.remoting>
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>

///异常信息
http://192.168.88.132:8190/eocDemoCommon.IServer
System.Net.WebException: 无法连接到远程服务器 ---> System.Net.Sockets.SocketExce
ption: 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。
  在 System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddre
ss socketAddress)
  在 System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP)
  在 System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Sock
et s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state,
IAsyncResult asyncResult, Int32 timeout, Exception& exception)
  --- 内部异常堆栈跟踪的结尾 ---

Server stack trace:
  在 System.Net.HttpWebRequest.GetRequestStream()
  在 System.Runtime.Remoting.Channels.Http.HttpClientTransportSink.ProcessAndSe
nd(IMessage msg, ITransportHeaders headers, Stream inputStream)
  在 System.Runtime.Remoting.Channels.Http.HttpClientTransportSink.ProcessMessa
ge(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransp
ortHeaders& responseHeaders, Stream& responseStream)
  在 System.Runtime.Remoting.Channels.SoapClientFormatterSink.SyncProcessMessag
e(IMessage msg)

Exception rethrown at [0]:
  在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage req
Msg, IMessage retMsg)
  在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgDa
ta, Int32 type)
  在 eocDemoCommon.ClientParam.get_User()
  在 eocDemoCommon.ServerImpl.CallFun(ClientParam para) 位置 F:\studytest\CShar


p学习\Remoting\eocDemoCommon\Class1.cs:行号 12
  在 System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(
IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInCont
ext, Object[]& outArgs)
  在 System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(R
untimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fE
xecuteInContext, Object[]& outArgs)
  在 System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMes
sage msg, Int32 methodPtr, Boolean fExecuteInContext)

Exception rethrown at [1]:
  在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage req
Msg, IMessage retMsg)
  在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgDa
ta, Int32 type)
  在 eocDemoCommon.IServer.CallFun(ClientParam para)
  在 eocDemoClient.Program.Main(String[] args) 位置 F:\studytest\CSharp学习\Rem
oting\eocDemoClient\Program.cs:行号 31


[解决办法]
先作个test() 无参数的方法,调用 下试一试,看下是否通讯正常。

热点排行