Ejemplo n.º 1
0
        public static void RegistRemotingObj(string channelName,  
                                                                int port, 
                                                                string typeName, 
                                                                string assembly,
                                                                 string url)
        {
            //Port
            IChannel chnl = ChannelServices.GetChannel(channelName);
            if (channel == null || chnl == null)
            {
                if (channel != null)
                    ChannelServices.UnregisterChannel(channel);
                if (chnl != null)
                    ChannelServices.UnregisterChannel(chnl);
                channel = new TcpServerChannel(channelName, port);
                ChannelServices.RegisterChannel(channel, false);
            }

            //Object Regist
            WellKnownServiceTypeEntry registerType = new WellKnownServiceTypeEntry(typeName, assembly, url, WellKnownObjectMode.Singleton);
            RemotingConfiguration.RegisterWellKnownServiceType(registerType);
            RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off;
            RemotingConfiguration.CustomErrorsEnabled(false);
            
        }
Ejemplo n.º 2
0
 /// <summary>
 /// when big boring button is clicked start to listen on port 9000
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void start_Click(object sender, EventArgs e)
 {
     TcpServerChannel channel = new TcpServerChannel(9000);
     ChannelServices.RegisterChannel(channel, false);
     WellKnownServiceTypeEntry remObj = new WellKnownServiceTypeEntry
     (
     typeof(RemoteApp.RemoteApp),
     "remoteapp",
     WellKnownObjectMode.Singleton
     );
     RemotingConfiguration.RegisterWellKnownServiceType(remObj);
 }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            TcpChannel remotingChannel = new TcpChannel(8888);

            ChannelServices.RegisterChannel(remotingChannel, false);

            WellKnownServiceTypeEntry remoteObject = new WellKnownServiceTypeEntry(typeof(RemoteMathExpanded), "rMath", WellKnownObjectMode.SingleCall);

            RemotingConfiguration.RegisterWellKnownServiceType(remoteObject);

            Console.WriteLine("Registered service");
            Console.WriteLine("Press any key to exit");
            Console.ReadLine();
        }
Ejemplo n.º 4
0
 private void registerChannel()
 {
     // set typefilterlevel to higher security
     SoapServerFormatterSinkProvider serverFormatter = new SoapServerFormatterSinkProvider();
     serverFormatter.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
     // setup dictionary with values
     Hashtable ht = new Hashtable();
     ht["name"] = "ServerChannel";
     ht["port"] = 9000;
     // create and register the channel
     HttpChannel channel = new HttpChannel(ht, null, serverFormatter);
     ChannelServices.RegisterChannel(channel, false);
     // register a wellknown type in singleton mode
     string identifier = "commBuffer";
     WellKnownObjectMode mode = WellKnownObjectMode.Singleton;
     WellKnownServiceTypeEntry entry = new WellKnownServiceTypeEntry(typeof(osgCommBuffer),
             identifier, mode);
      RemotingConfiguration.RegisterWellKnownServiceType(entry);
 }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            // create a TCP channel and bind it to port 8888
            TcpChannel remotingChannel = new TcpChannel(8888);

            // register the channel, the second parameter is ensureSecurity
            // I have set it to false to disable encryption and signing
            // for more information see section Remarks in https://msdn.microsoft.com/en-us/library/ms223155(v=vs.90).aspx
            ChannelServices.RegisterChannel(remotingChannel, false);

            // create a new servicetype of type RemoteMath named "rMath" and of type SingleCall
            // SingleCall: a new object will be created for each call
            // as opposed to WellKnownObjectMode.Singleton where there is one object for all calls (and clients)
            WellKnownServiceTypeEntry remoteObject = new WellKnownServiceTypeEntry(typeof(RemoteMath), "rMath", WellKnownObjectMode.SingleCall);

            // register the remoteObject servicetype
            RemotingConfiguration.RegisterWellKnownServiceType(remoteObject);

            Console.WriteLine("Registered service");
            Console.WriteLine("Press any key to exit");
            Console.ReadLine();

        }
 private bool CheckForWellKnownServiceEntryWithType(string typeName, string asmName)
 {
     foreach (DictionaryEntry entry in this._wellKnownExportInfo)
     {
         WellKnownServiceTypeEntry entry2 = (WellKnownServiceTypeEntry)entry.Value;
         if (typeName == entry2.TypeName)
         {
             bool flag = false;
             if (asmName == entry2.AssemblyName)
             {
                 flag = true;
             }
             else if ((string.Compare(entry2.AssemblyName, 0, asmName, 0, asmName.Length, StringComparison.OrdinalIgnoreCase) == 0) && (entry2.AssemblyName[asmName.Length] == ','))
             {
                 flag = true;
             }
             if (flag)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
 public static void RegisterWellKnownServiceType(WellKnownServiceTypeEntry entry)
 {
     Contract.Requires(entry != null);
     Contract.Requires(entry.AssemblyName != null);
     Contract.Requires(entry.ObjectUri != null);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Publishes this object for remoting.
        /// </summary>
        /// <param name="objectUri">The remoting uri of the object.</param>
        /// <param name="createDefaultChannels">
        /// Determinates if the default channels should be created or not.
        /// <seealso cref="RemotingConstants"/>
        /// </param>
        public void Start(string objectUri, bool createDefaultChannels)
        {
            if (createDefaultChannels)
            {
                // Register default channel for remote access
                Hashtable properties = new Hashtable();
                properties["name"] = RemotingConstants.DefaultServiceChannelName;
                properties["port"] = RemotingConstants.DefaultServicePort;
                IChannel currentChannel = RemotingConstants.GetDefaultChannel(properties);
                ChannelServices.RegisterChannel(currentChannel, false);
            }

            WellKnownServiceTypeEntry serviceTypeEntry = new WellKnownServiceTypeEntry(
                GetType(),
                objectUri,
                WellKnownObjectMode.Singleton);
            RegisterService(InnerHandler);
            RemotingConfiguration.RegisterWellKnownServiceType(serviceTypeEntry);
        }
Ejemplo n.º 9
0
            [System.Security.SecurityCritical]  // auto-generated
            internal void AddWellKnownEntry(WellKnownServiceTypeEntry entry, bool fReplace)
            {
                if (CheckForRedirectedClientType(entry.TypeName, entry.AssemblyName))
                {
                    throw new RemotingException(
                        String.Format(
                            CultureInfo.CurrentCulture, Environment.GetResourceString(
                                "Remoting_Config_CantUseRedirectedTypeForWellKnownService"),
                            entry.TypeName, entry.AssemblyName));
                }
            
                String key = entry.ObjectUri.ToLower(CultureInfo.InvariantCulture);
                
                if (fReplace)
                {
                    // Registering a well known object twice replaces the old one, so
                    //   we null out the old entry in the identity table after adding
                    //   this one. The identity will be recreated the next time someone
                    //   asks for this object.
                    _wellKnownExportInfo[key] = entry;

                    IdentityHolder.RemoveIdentity(entry.ObjectUri);
                }
                else
                {
                    _wellKnownExportInfo.Add(key, entry);
                }

            }
Ejemplo n.º 10
0
        public static void RegisterWellKnownServiceType(Type type, string objectUri, WellKnownObjectMode mode)
        {
            WellKnownServiceTypeEntry entry = new WellKnownServiceTypeEntry(type, objectUri, mode);

            RemotingConfiguration.RegisterWellKnownServiceType(entry);
        }
Ejemplo n.º 11
0
        //解析WellKnown对象
        void ParseWellKnownServerObjectSection(XmlNode root)
        {
            foreach (XmlNode node in root.ChildNodes)
            {
                if (node.NodeType == XmlNodeType.Comment) continue;
                if (node.Name != "add") continue;

                string objectUri = base.GetStringAttribute(node, "objectUri");
                if (string.IsNullOrEmpty(objectUri)) continue;

                string fullTypeName = base.GetStringAttribute(node, "type");
                if (string.IsNullOrEmpty(fullTypeName)) continue;

                string mode = base.GetStringAttribute(node, "mode").ToLower();
                

                string typeName = fullTypeName.Split(',')[0];
                string assemblyName = string.Empty;

                if (fullTypeName.IndexOf(',') != -1)
                {
                    assemblyName = fullTypeName.Split(',')[1];
                }
                else
                {
                    Assembly assembly = ReflectUtil.FindAssemblyFromAppDirectory(typeName);
                    if (assembly != null)
                        assemblyName = assembly.FullName;
                }

                WellKnownObjectMode objectMode = WellKnownObjectMode.Singleton;
                if (mode == "singlecall")
                    objectMode = WellKnownObjectMode.SingleCall;

                WellKnownServiceTypeEntry wse = new WellKnownServiceTypeEntry(typeName, assemblyName, objectUri, objectMode);
                si.AddWellKnownObject(wse);
            }
        }
 public static void RegisterWellKnownServiceType(WellKnownServiceTypeEntry entry)
 {
   Contract.Requires(entry != null);
   Contract.Requires(entry.AssemblyName != null);
   Contract.Requires(entry.ObjectUri != null);
 }
Ejemplo n.º 13
0
        public int Run(string[] args)
        {
            bool bouncingRequest = false;
            var options = args.Switches();
            var parameters = args.Parameters();

            foreach (var arg in options.Keys)
            {
                var argumentParameters = options[arg];

                switch (arg)
                {
                    case "load-config":
                        // all ready done, but don't get too picky.
                        break;

                    case "nologo":
                        this.Assembly().SetLogo(string.Empty);
                        break;

                    case "help":
                        return Help();

                    case "output-file":
                        _traceFile = Path.GetFullPath(argumentParameters.LastOrDefault());
                        break;

                    case "bounce":
                        // whoa there, this is an internal bounce request
                        bouncingRequest = true;
                        _ticket = int.Parse(argumentParameters.LastOrDefault());
                        break;

                    default:
                        return Fail("Unknown parameter [--{0}]", arg);
                }
            }

            if (parameters.Count() < 1 && !bouncingRequest)
            {
                return Fail("Missing Command. \r\n\r\n    Use --help for command line help.");
            }

            //
            // Get the rest of the command line
            //
            var application = string.Empty;
            var cmdline = string.Empty;

            if (!bouncingRequest)
            {
                application = Helpers.FindInPath(parameters.First());

                if( !File.Exists(application)) {
                    return Fail("Unable to start given command line. \r\n\r\n    Can not find executable [{0}]", application);
                }

                cmdline = parameters.Skip(1).Aggregate("\"" + application + "\" ", (current, i) => current + (i.Contains(" ") ? "\"" + i + "\" " : i + " ")).Trim();
                Logo();
            }

            //
            // Register our .NET remoting "scribe" and related comm channel
            //
            if (!bouncingRequest)
            {
                _channel = new IpcChannel("CoAppTraceIpc");
                WellKnownServiceTypeEntry wkst = new WellKnownServiceTypeEntry(typeof(Scribe),
                    "Scribe", WellKnownObjectMode.Singleton);

                RemotingConfiguration.RegisterWellKnownServiceType(wkst);
                ChannelServices.RegisterChannel(_channel, false);
            }

            //
            // Create the first instance
            //
            var scribe = (IScribe)Activator.GetObject(typeof(IScribe), "ipc://CoAppTraceIpc/Scribe");
            scribe.Ping();

            //
            // Detour and launch the target process.
            //
            // If we're bouncing a request, we need to ensure we restore all the
            // original parameters before continuing.
            //
            IntPtr ppi = Marshal.AllocHGlobal(Constants.SizeOfProcessInformation);
            Helpers.RtlZeroMemory(ppi, Constants.SizeOfProcessInformation);

            IntPtr psi = Marshal.AllocHGlobal(Constants.SizeOfStartupInformation);
            Helpers.RtlZeroMemory(psi, Constants.SizeOfStartupInformation);
            Marshal.WriteInt32(psi, 0, Constants.SizeOfStartupInformation);

            Scribe.State state = new Scribe.State();
            if (bouncingRequest)
            {
                state = scribe.RetrieveState(_ticket);

                application = state.ApplicationName;
                cmdline = state.CommandLine;

                var processInfo = state.ProcessInformation;
                var startupInfo = state.StartupInformation;

                IntPtr lpDesktop = string.IsNullOrEmpty(state.Desktop) ? IntPtr.Zero : Marshal.StringToHGlobalUni(state.Desktop);
                IntPtr lpTitle = string.IsNullOrEmpty(state.Title) ? IntPtr.Zero : Marshal.StringToHGlobalUni(state.Title);

                startupInfo.lpDesktop = lpDesktop;
                startupInfo.lpTitle = lpTitle;

                // Leaky. But not really a problem.
                Marshal.StructureToPtr(processInfo, ppi, false);
                Marshal.StructureToPtr(startupInfo, psi, false);
                //
                // The bounce process has a console of its own (console subsystem).
                // We need to destroy it and latch onto our parent's existing one.
                //
                // Kernel32.FreeConsole();
                // Kernel32.AttachConsole(-1);
            }

            IntPtr lpApplication = Marshal.StringToHGlobalUni(application);
            IntPtr lpCmdLine = Marshal.StringToHGlobalUni(cmdline);

            bool bounced;

            Detours.DetourCreateProcessWithDll(lpApplication, lpCmdLine, IntPtr.Zero, IntPtr.Zero, Constants.DetoursDllName,
                Constants.DetouredDllName,Constants.CoAppTraceHost, 1, 0, IntPtr.Zero, IntPtr.Zero, psi, ppi, out bounced);

            var pi = (PROCESS_INFORMATION)Marshal.PtrToStructure(ppi, typeof(PROCESS_INFORMATION));
            Debug.Assert(pi.dwProcessId != 0, "Process ID 0 detected.");

            if (bouncingRequest) {

                scribe.DocumentNewProcess(state.OriginalParentProcessId, (int)pi.dwProcessId, cmdline, application, Environment.CurrentDirectory);

                // we need to give the child app time enough to get going before doing anything...
                // Thread.Sleep(1000);

                if (state.IsConsole) {
                    try {
                        Scribe.GetStartedProcessById((int) pi.dwProcessId).WaitForExit();
                    }
                    catch (Exception e) {
                        /// meh. it dies, it dies.
                        // Console.WriteLine("Exception'd. {0}", e.Message);
                    }
                }
            }
            else {
                if (!bounced) {
                    scribe.DocumentNewProcess((int) pi.dwProcessId, cmdline, application, Environment.CurrentDirectory);
                }

                //
                // Wait for the spawned process (and its children) to terminate completely.
                //
                scribe.Finished.WaitOne();

                //
                // Save the trace output to disk.
                //
                scribe.Write(_traceFile.format((int) pi.dwProcessId));
                using (new ConsoleColors(ConsoleColor.White, ConsoleColor.Black)) {
                    Console.WriteLine("TRACE COMPLETE");
                    Console.WriteLine("TRACE File: {0} ", _traceFile.format((int) pi.dwProcessId).GetFullPath());
                }
            }

            return 0;
        }
 internal void AddWellKnownEntry(WellKnownServiceTypeEntry entry, bool fReplace)
 {
     if (this.CheckForRedirectedClientType(entry.TypeName, entry.AssemblyName))
     {
         throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Config_CantUseRedirectedTypeForWellKnownService"), new object[] { entry.TypeName, entry.AssemblyName }));
     }
     string key = entry.ObjectUri.ToLower(CultureInfo.InvariantCulture);
     if (fReplace)
     {
         this._wellKnownExportInfo[key] = entry;
         IdentityHolder.RemoveIdentity(entry.ObjectUri);
     }
     else
     {
         this._wellKnownExportInfo.Add(key, entry);
     }
 }
 internal WellKnownServiceTypeEntry[] GetRegisteredWellKnownServiceTypes()
 {
     WellKnownServiceTypeEntry[] entryArray = new WellKnownServiceTypeEntry[this._wellKnownExportInfo.Count];
     int num = 0;
     foreach (DictionaryEntry entry in this._wellKnownExportInfo)
     {
         WellKnownServiceTypeEntry entry2 = (WellKnownServiceTypeEntry) entry.Value;
         WellKnownServiceTypeEntry entry3 = new WellKnownServiceTypeEntry(entry2.TypeName, entry2.AssemblyName, entry2.ObjectUri, entry2.Mode) {
             ContextAttributes = entry2.ContextAttributes
         };
         entryArray[num++] = entry3;
     }
     return entryArray;
 }
 internal static void RegisterWellKnownServiceType(WellKnownServiceTypeEntry entry)
 {
     string typeName = entry.TypeName;
     string assemblyName = entry.AssemblyName;
     string objectUri = entry.ObjectUri;
     WellKnownObjectMode mode = entry.Mode;
     lock (Info)
     {
         Info.AddWellKnownEntry(entry);
     }
 }
 internal void StoreWellKnownExports(RemotingXmlConfigFileData configData)
 {
     foreach (RemotingXmlConfigFileData.ServerWellKnownEntry entry in configData.ServerWellKnownEntries)
     {
         WellKnownServiceTypeEntry entry2 = new WellKnownServiceTypeEntry(entry.TypeName, entry.AssemblyName, entry.ObjectURI, entry.ObjectMode) {
             ContextAttributes = null
         };
         RemotingConfigHandler.RegisterWellKnownServiceType(entry2);
     }
 }
	// Register a well known service type entry.
	public static void RegisterWellKnownServiceType
				(WellKnownServiceTypeEntry entry)
			{
				if(entry == null)
				{
					throw new ArgumentNullException("entry");
				}
				lock(typeof(RemotingConfiguration))
				{
					EnsureLoaded();
					if(registeredServiceTypes == null)
					{
						registeredServiceTypes = new Hashtable();
					}
					registeredServiceTypes[entry.ObjectType] = entry;
				}
			}
Ejemplo n.º 19
0
		public static WellKnownServiceTypeEntry[] GetRegisteredWellKnownServiceTypes () 
		{
			lock (channelTemplates)
			{
				WellKnownServiceTypeEntry[] entries = new WellKnownServiceTypeEntry[wellKnownServiceEntries.Count];
				wellKnownServiceEntries.Values.CopyTo (entries,0);
				return entries;
			}
		}
 public static void RegisterWellKnownServiceType(WellKnownServiceTypeEntry entry)
 {
     RemotingConfigHandler.RegisterWellKnownServiceType(entry);    
 } // RegisterWellKnownServiceType
Ejemplo n.º 21
0
		public static void RegisterWellKnownServiceType (WellKnownServiceTypeEntry entry) 
		{
			lock (channelTemplates)
			{
				wellKnownServiceEntries [entry.ObjectUri] = entry;
				RemotingServices.CreateWellKnownServerIdentity (entry.ObjectType, entry.ObjectUri, entry.Mode);
			}
		}
Ejemplo n.º 22
0
            } // GetRegisteredActivatedServiceTypes


            internal WellKnownServiceTypeEntry[] GetRegisteredWellKnownServiceTypes()
            {
                WellKnownServiceTypeEntry[] entries =
                    new WellKnownServiceTypeEntry[_wellKnownExportInfo.Count];

                int co = 0;
                foreach (DictionaryEntry dictEntry in _wellKnownExportInfo)
                {
                    WellKnownServiceTypeEntry entry = (WellKnownServiceTypeEntry)dictEntry.Value;
                    
                    WellKnownServiceTypeEntry wkste =
                        new WellKnownServiceTypeEntry(
                            entry.TypeName, entry.AssemblyName,
                            entry.ObjectUri, entry.Mode);

                    wkste.ContextAttributes = entry.ContextAttributes;
                    
                    entries[co++] = wkste;
                }
                    
                return entries;
            } // GetRegisteredWellKnownServiceTypes
Ejemplo n.º 23
0
 public static void RegisterWellKnownServiceType(WellKnownServiceTypeEntry entry)
 {
     RemotingConfigHandler.RegisterWellKnownServiceType(entry);
 }
 public static void RegisterWellKnownServiceType(Type type, string objectUri, WellKnownObjectMode mode)
 {
     WellKnownServiceTypeEntry entry = new WellKnownServiceTypeEntry(type, objectUri, mode);
     RegisterWellKnownServiceType(entry);
 }
 public static void RegisterWellKnownServiceType(
     Type type, String objectUri, WellKnownObjectMode mode)
 {
     WellKnownServiceTypeEntry wke = 
         new WellKnownServiceTypeEntry(type, objectUri, mode);        
     RemotingConfiguration.RegisterWellKnownServiceType(wke); 
 } // RegisterWellKnownServiceType
Ejemplo n.º 26
0
 /// <summary>
 /// 加入一个WellKnown对象实体
 /// </summary>
 /// <param name="entry"></param>
 public void AddWellKnownObject(WellKnownServiceTypeEntry entry)
 {
     if (_WellKnownObjectCollection.ContainsKey(entry.ObjectUri)) return;
     _WellKnownObjectCollection.Add(entry.ObjectUri, entry);
 }
Ejemplo n.º 27
0
 [System.Security.SecurityCritical]  // auto-generated
 internal void StoreWellKnownExports(RemotingXmlConfigFileData configData)
 {
     // <
 
     foreach (RemotingXmlConfigFileData.ServerWellKnownEntry entry in configData.ServerWellKnownEntries)
     {
         WellKnownServiceTypeEntry wke = 
             new WellKnownServiceTypeEntry(
                 entry.TypeName, entry.AssemblyName, entry.ObjectURI, 
                 entry.ObjectMode);
         wke.ContextAttributes = null;
     
         // Register the well known entry but do not startup the object
         RemotingConfigHandler.RegisterWellKnownServiceType(wke);
     }
 } // StoreWellKnownExports
Ejemplo n.º 28
0
 public static void RegisterWellKnownServiceType(WellKnownServiceTypeEntry entry)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 29
0
 [System.Security.SecurityCritical]  // auto-generated
 internal void AddWellKnownEntry(WellKnownServiceTypeEntry entry)
 {
     AddWellKnownEntry(entry, true);                
 }
Ejemplo n.º 30
0
		public static void init() 
		{		   
		   if (instance == null) {
			  instance = new WebBackEnd();

			  if (tch1 == null) {
			  	
			  	tch1 = new TcpChannel(8347);

			  	//Register TCP Channel Listener
		  	  	ChannelServices.RegisterChannel(tch1);	

			  	WellKnownServiceTypeEntry WKSTE = 
			  		new WellKnownServiceTypeEntry(typeof(WebBackEnd),
				 		"WebBackEnd.rem", WellKnownObjectMode.Singleton);
			  	RemotingConfiguration.ApplicationName="beagled";
			  	RemotingConfiguration.RegisterWellKnownServiceType(WKSTE);
			  }
		   }
		}
Ejemplo n.º 31
0
 [System.Security.SecurityCritical]  // auto-generated
 internal static void RegisterWellKnownServiceType(WellKnownServiceTypeEntry entry)
 {
     BCLDebug.Trace("REMOTE", "Adding well known service type for " + entry.ObjectUri);
     // <
     String serverType = entry.TypeName;
     String asmName = entry.AssemblyName;
     String URI = entry.ObjectUri;
     WellKnownObjectMode mode = entry.Mode;
     
     lock (Info)
     {            
         // We make an entry in our config tables so as to keep
         // both the file-based and programmatic config in [....].
         Info.AddWellKnownEntry(entry);
     }
 } // RegisterWellKnownServiceType
 internal void AddWellKnownEntry(WellKnownServiceTypeEntry entry)
 {
     this.AddWellKnownEntry(entry, true);
 }