Exemple #1
0
        static void Main(string[] args)
        {
            // Create the WcfClient connector
            WcfConnectionStringBuilder builder = new WcfConnectionStringBuilder();

            builder.EndpointName = "ApplicationClient";
            WcfClientConnector client = new WcfClientConnector(builder.GenerateConnectionString()); // Endpoint name should match the ep name in app.config

            // Setup the formatter
            client.Formatter = new MARC.Everest.Formatters.XML.ITS1.Formatter();
            client.Formatter.GraphAides.Add(new DatatypeFormatter());

            // We want the service to validate our messages, not the formatter, so lets just turn off the
            // formatter validation for now
            (client.Formatter as MARC.Everest.Formatters.XML.ITS1.Formatter).ValidateConformance = false;

            // Open the connection
            client.Open();

            // Start the async send
            IAsyncResult iaSendResult = client.BeginSend(CreateInstance(), null, null);

            Console.WriteLine("Formatting and sending, please wait...");
            iaSendResult.AsyncWaitHandle.WaitOne(); // Wait until the response is received

            // Now we have to check that the message was actually sent to the remote system
            WcfSendResult sndResult = client.EndSend(iaSendResult) as WcfSendResult;

            // The result of sending the message wasn't good.
            if (sndResult.Code != ResultCode.Accepted && sndResult.Code != ResultCode.AcceptedNonConformant)
            {
                Console.WriteLine("The message wasn't sent!");
            }
            else // The connector has sent the message
            {
                // Receive the result (this involves waiting...)
                IAsyncResult iaRcvResult = client.BeginReceive(sndResult, null, null);
                Console.WriteLine("Parsing result...");
                iaRcvResult.AsyncWaitHandle.WaitOne(); // Wait for deserialization
                WcfReceiveResult rcvResult = client.EndReceive(iaRcvResult) as WcfReceiveResult;

                // Now lets print out the structure
                client.Formatter.Graph(Console.OpenStandardOutput(), rcvResult.Structure);
            }

            // Close the connection
            client.Close();

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Exemple #2
0
        // Main function
        public static void Main(string[] args)
        {
            Assembly.Load(new AssemblyName("MARC.Everest.RMIM.CA.R020402"));

            // Instantiate the connector
            WcfServerConnector connector = new WcfServerConnector();

            // Assign the formatter
            connector.Formatter = new MARC.Everest.Formatters.XML.ITS1.Formatter();
            connector.Formatter.GraphAides.Add(
                new DatatypeFormatter()
                );

            // Subscribe to the message available event
            connector.MessageAvailable += new EventHandler <UnsolicitedDataEventArgs>(
                connector_MessageAvailable
                );

            // Open and start the connector
            try
            {
                WcfConnectionStringBuilder builder = new WcfConnectionStringBuilder();
                builder.ServiceName        = "ApplicationService";
                connector.ConnectionString = builder.GenerateConnectionString();
                connector.Open();
                connector.Start();

                Console.WriteLine("Server started, press any key to close...");
                Console.ReadKey();

                // Teardown
                connector.Stop();
                connector.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
Exemple #3
0
        /// <summary>
        /// Initialize the client connector
        /// </summary>
        private void InitializeConnector()
        {
            // Build connection string
            WcfConnectionStringBuilder csBuilder = new WcfConnectionStringBuilder();

            csBuilder.EndpointName = "pdqSupplier";

            // Create formatter
            XmlIts1Formatter fmtr = new XmlIts1Formatter()
            {
                ValidateConformance = false
            };

            fmtr.GraphAides.Add(new CanadianDatatypeFormatter()
            {
                ValidateConformance = false
            });

            // Setup and open
            this.m_clientConnector           = new WcfClientConnector(csBuilder.GenerateConnectionString());
            this.m_clientConnector.Formatter = fmtr;
            this.m_clientConnector.Open();
        }