public XmlBlasterClient() { // Client xmlBlasterClientProxy = (IXmlBlasterClient)XmlRpcProxyGen.Create(typeof(IXmlBlasterClient)); xmlBlasterClientProtocol = (XmlRpcClientProtocol)xmlBlasterClientProxy; // Server for Callback //RemotingConfiguration.Configure("xmlrpc.exe.config"); HttpChannel channel = null; try { //int port = FindFreeHttpPort( 9090 ) ; //Debug.WriteLine( "FindFreeHttpPort() found port "+port ); int port = 0; ListDictionary channelProperties = new ListDictionary(); channelProperties.Add("port", port); channel = new HttpChannel( channelProperties, new CookComputing.XmlRpc.XmlRpcClientFormatterSinkProvider(), new CookComputing.XmlRpc.XmlRpcServerFormatterSinkProvider(null, null) //new SoapClientFormatterSinkProvider(), //new SoapServerFormatterSinkProvider() ); } catch (Exception ex) { // Listener config failed : Une seule utilisation de chaque adresse de socket (protocole/adresse réseau/port) est habituellement autorisée Debug.WriteLine("Listener config failed : " + ex.Message); XmlBlasterException.HandleException(new Exception("Listener config failed.", ex)); } ChannelServices.RegisterChannel(channel); RemotingConfiguration.RegisterWellKnownServiceType( typeof(XmlBlasterCallback), "XmlBlasterCallback", WellKnownObjectMode.Singleton ); // Print out the urls for HelloServer. string[] urls = channel.GetUrlsForUri("XmlBlasterCallback"); foreach (string url in urls) { System.Console.WriteLine("url: {0}", url); } //url: http://127.0.0.1:1038/XmlBlasterCallback if (urls.Length != 1) { XmlBlasterException.HandleException(new Exception("XmlBlasterCallback server, failed to retreive url.")); } this.callbackServerUri = new Uri(urls[0]); }
public XmlBlasterClient() { // // Client // xmlBlasterClientProxy = (IXmlBlasterClient)XmlRpcProxyGen.Create(typeof(IXmlBlasterClient)); xmlBlasterClientProtocol = (XmlRpcClientProtocol)xmlBlasterClientProxy; // // Callback Server // // On peut le faire depuis un fichier //RemotingConfiguration.Configure("xmlrpc.exe.config"); // Ou bien à la mano try { //int port = FindFreeHttpPort( 9090 ) ; //logger.Debug( "FindFreeHttpPort() found port "+port ); // port = 0 pour que le système assigne automatiquement un port non-utilisé. int port = 0; ListDictionary channelProperties = new ListDictionary(); channelProperties.Add("port", port); httpChannel = new HttpChannel( channelProperties, new CookComputing.XmlRpc.XmlRpcClientFormatterSinkProvider(), new CookComputing.XmlRpc.XmlRpcServerFormatterSinkProvider(null, null) //new SoapClientFormatterSinkProvider(), //new SoapServerFormatterSinkProvider() ); } catch (Exception ex) { // Listener config failed : Une seule utilisation de chaque adresse de socket (protocole/adresse réseau/port) est habituellement autorisée XmlBlasterException.HandleException(new Exception("XmlBlaster callback server, Listener config failed.", ex)); } try { ChannelServices.RegisterChannel(httpChannel); } catch (System.Runtime.Remoting.RemotingException) { // Pas grave: The channel has already been registered. } catch (Exception ex) { XmlBlasterException.HandleException(new Exception("XmlBlasterCallback server, failed to RegisterChannel.", ex)); } RemotingConfiguration.RegisterWellKnownServiceType( typeof(XmlBlasterCallback), "XmlBlasterCallback", WellKnownObjectMode.Singleton ); // Comme on a pas indiqué de port, celui-ci a été assigné automatiquement. // Il nous faut donc retrouver l'url afin de pouvoir la transmettre dans le Qos de connexion. string[] urls = httpChannel.GetUrlsForUri("XmlBlasterCallback"); foreach (string url in urls) { logger.Debug("XmlBlasterCallback url: {0}", url); } //url: http://192.168.0.151:4808/XmlBlasterCallback if (urls.Length != 1) { XmlBlasterException.HandleException(new Exception("XmlBlasterCallback server, failed to retreive url.")); } this.callbackServerUri = new Uri(urls[0]); }