예제 #1
0
        public virtual void WriteProxy(object o, Type ot)
        {
            if (!RemotingServices.IsTransparentProxy(o))
            {
                Console.WriteLine("o {0} ot {1} is not transparent proxy!", o, ot);
                throw new InvalidOperationException("object which is not a transparent proxy passed to WriteProxy, type " + ot);
            }

            ObjRef or = RemotingServices.GetObjRefForProxy((System.MarshalByRefObject)o);

            Ice.Identity proxy_ident = new Ice.Identity(or.URI.StartsWith("/") ? or.URI.Substring(1) : or.URI);
            Ice.Endpoint proxy_ep    = null;

            foreach (object cdo in or.ChannelInfo.ChannelData)
            {
                ChannelDataStore cd = cdo as ChannelDataStore;
                if (cd == null)
                {
                    continue;
                }
                foreach (string ch_uri in cd.ChannelUris)
                {
                    string host;
                    int    port;
                    string uri;

                    if (IceChannelUtils.ParseIceURL(ch_uri, out host, out port, out uri))
                    {
                        proxy_ep          = new Ice.TcpEndpoint(host, port);
                        proxy_ep.Incoming = true;
                        break;
                    }
                }
            }

            if (proxy_ep == null)
            {
                throw new InvalidOperationException("Couldn't find valid Ice endpoint/channel for " + o);
            }

            Ice.ProxyData pd = new Ice.ProxyData();
            pd.id     = proxy_ident;
            pd.facet  = new string[0];
            pd.mode   = ProxyMode.Twoway; // FIXME -- do I need to send multiple proxy things here?
            pd.secure = false;

            WriteStruct(pd);
            WriteSize(1);       // one endpoint follows

            // tcp endpoint encapsulation
            WriteObject((short)1); // it's a TCP endpoint
            BeginEncapsulation();
            Ice.TcpEndpoint te = proxy_ep as Ice.TcpEndpoint;
            Write(te.host);
            WriteObject(te.port);
            WriteObject(te.timeout);
            WriteObject(te.compress);
            EndEncapsulation();
        }
예제 #2
0
        public Ice.Object ReadObjectProxy(Type t)
        {
            // read the proxy data header
            Ice.ProxyData pd = (Ice.ProxyData)ReadObject(typeof(Ice.ProxyData));

            // next read a size; if it's > 0, it's the number
            // of proxy endpoints that follow.  if it's == 0,
            // it's followed by a string identifying the object
            // locator.
            int sz = ReadSize();

            if (sz == 0)
            {
                string locator = ReadString();
                Console.WriteLine("Proxy sz == 0, locator = " + locator);
                return(null);
            }

            for (int i = 0; i < sz; i++)
            {
                short ptype = (short)ReadObject(typeof(short));
                if (ptype == 1)                   // tcp endpoint
                {
                    int    capSize  = ReadEncapsulationHeader();
                    string host     = ReadString();
                    int    port     = ReadInt32();
                    int    timeout  = ReadInt32();
                    bool   compress = ReadBoolean();

                    string url = "ice://" + host + ":" + port + "/" + pd.id.name;
                    Trace.WriteLine("ReadObjectProxy: Activating " + url);
                    // activate the object
                    return((Ice.Object)Activator.GetObject(t, url));
                }
                else if (ptype == 2)              // ssl endpoint
                {
                    Console.WriteLine("ReadObjectProxy: found SSL endpoint; ignoring");
                }
                else if (ptype == 3)              // udp endpoint
                {
                    Console.WriteLine("ReadObjectProxy: found UDP endpoint; ignoring");
                }
            }

            return(null);
        }
예제 #3
0
    public virtual void WriteProxy (object o, Type ot) {
      if (!RemotingServices.IsTransparentProxy (o)) {
        Console.WriteLine ("o {0} ot {1} is not transparent proxy!", o, ot);
        throw new InvalidOperationException ("object which is not a transparent proxy passed to WriteProxy, type " + ot);
      }

      ObjRef or = RemotingServices.GetObjRefForProxy ((System.MarshalByRefObject) o);
      Ice.Identity proxy_ident = new Ice.Identity (or.URI.StartsWith("/") ? or.URI.Substring(1) : or.URI);
      Ice.Endpoint proxy_ep = null;

      foreach (object cdo in or.ChannelInfo.ChannelData) {
        ChannelDataStore cd = cdo as ChannelDataStore;
        if (cd == null)
          continue;
        foreach (string ch_uri in cd.ChannelUris) {
          string host;
          int port;
          string uri;

          if (IceChannelUtils.ParseIceURL (ch_uri, out host, out port, out uri)) {
            proxy_ep = new Ice.TcpEndpoint (host, port);
            proxy_ep.Incoming = true;
            break;
          }
        }
      }
      
      if (proxy_ep == null) {
        throw new InvalidOperationException ("Couldn't find valid Ice endpoint/channel for " + o);
      }

      Ice.ProxyData pd = new Ice.ProxyData();
      pd.id = proxy_ident;
      pd.facet = new string[0];
      pd.mode = ProxyMode.Twoway; // FIXME -- do I need to send multiple proxy things here?
      pd.secure = false;

      WriteStruct (pd);
      WriteSize (1);            // one endpoint follows

      // tcp endpoint encapsulation
      WriteObject ((short) 1);  // it's a TCP endpoint
      BeginEncapsulation();
      Ice.TcpEndpoint te = proxy_ep as Ice.TcpEndpoint;
      Write (te.host);
      WriteObject (te.port);
      WriteObject (te.timeout);
      WriteObject (te.compress);
      EndEncapsulation();
    }