Ejemplo n.º 1
0
        public void Publish(string topic, string xmlMessage)
        {
            Debug.WriteLine("XmlBlaster.Publish()");

            try
            {
                string key = "<key oid=\"" + topic + "\" contentMime=\"text/xml\" >\n";
                key += "<sender>" + uniqueId + "</sender>\n";
                key += "</key>";

                string qos = "<qos />";

                string result = xmlBlasterClientProxy.Publish(this.sessionId, key, xmlMessage, qos);

                //Debug.Write( "Publish Result :" );
                //Debug.WriteLine( result );

                /*
                 *      XmlBlaster.Publish()
                 *      Publish Result :
                 *      <qos>
                 *      <key oid='demo.csharp.drawing'/>
                 *      <rcvTimestamp nanos='1131972554614000000'/>
                 *      <isPublish/>
                 *      </qos>
                 */
            }
            catch (Exception ex)
            {
                XmlBlasterException.HandleException(ex);
            }
        }
Ejemplo n.º 2
0
        public void Connect(string url, string username, string password)
        {
            Debug.WriteLine("XmlBlaster.Connect()");

            this.Url = url;              // Set xml-rpc server url

            // construct authentification data
            QosConnect qos;

            try
            {
                // try connect (login)
                qos = new QosConnect(username, password, this.callbackServerUri.ToString());
                string result = xmlBlasterClientProxy.Connect(qos.ToString());
                //Debug.Write( "Connect Result :" );
                //Debug.WriteLine( result );
                QosConnectResult qosRes = new QosConnectResult(result);
                this.sessionId = qosRes.SessionId;

                // TODO: sessionId should be secret !
                // do something better ;o)
                Random rnd = new Random( );
                this.uniqueId = rnd.NextDouble().ToString();
            }
            catch (Exception ex)
            {
                XmlBlasterException.HandleException(ex);
            }
        }
Ejemplo n.º 3
0
        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]);
        }
Ejemplo n.º 4
0
        public void Disconnect()
        {
            Debug.WriteLine("XmlBlaster.Disconnect()");

            // construct authentification data
            string qos = @"
				<qos>
					<deleteSubjectQueue>true</deleteSubjectQueue>
					<clearSessions>true</clearSessions>
				</qos>"                ;

            try
            {
                xmlBlasterClientProxy.Disconnect(this.sessionId, qos);
            }
            catch (Exception ex)
            {
                XmlBlasterException.HandleException(ex);
            }
        }
Ejemplo n.º 5
0
        public void Subscribe(string topic)
        {
            Debug.WriteLine("XmlBlaster.Subscribe()");

            try
            {
                string key = "<key oid=\"" + topic + "\" />\n";
                string qos = @"<qos>
					<local>false</local>
					</qos>"                    ;

                string result = xmlBlasterClientProxy.Subscribe(this.sessionId, key, qos);

                Debug.Write("Subscribe Result :");
                Debug.WriteLine(result);
            }
            catch (Exception ex)
            {
                XmlBlasterException.HandleException(ex);
            }
        }