mercredi 4 novembre 2015

How to change WCF WS w/ IsOneWay=true into request-response

To all,

I have a one way WCF WS built in VS 2008 working. This web service calls an IBM MQ service and does retrieve the response via MQ. I've returned the string all the way back to the WCF Service component. I need to know how to change the service from IsOneWay = true to a request-response pattern so I can get the XML response back to the SoapUI response pane.

Here is the code for the WCF Service:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.ServiceModel.Channels;
    using System.Text;

    namespace SOATesting
    {
        // NOTE: If you change the interface name "IService1" here, you must       also update the reference to "IService1" in Web.config.
        [ServiceContract(Namespace = "http://ift.tt/1OoHyMI")]
        public interface IService1
        {
            [OperationContract(IsOneWay = true)]
            void RunTest(Message msg);        

        }
    }

And here is RunTest:
    namespace SOATesting
    {
    // NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in Web.config and in the associated .svc file.
        public class Service1 : IService1
        {
                public void RunTest(Message msg)
            {
                string serviceName;
                string queueManager;
                string requestQueue;
                string requestMessage;
                string responseMsge = null;

                requestMessage = msg.ToString();

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(requestMessage);

                XmlNamespaceManager nsmgr = new     XmlNamespaceManager(doc.NameTable);
                nsmgr.AddNamespace("cfg-hdr", "http://ift.tt/1MzkMLJ");
                nsmgr.PushScope();

                serviceName = doc.SelectSingleNode("//cfg-hdr:ServiceName",   nsmgr).InnerText;
                queueManager = doc.SelectSingleNode("//cfg-hdr:OrigReplyToQMgr", nsmgr).InnerText;
                requestQueue = doc.SelectSingleNode("//cfg-hdr:OrigReplyToQ", nsmgr).InnerText;

                Engine eng = new Engine();

                try
                {
                    eng.Put(serviceName, requestQueue, requestMessage,  queueManager);
                    responseMsge = eng.ReadMsg();
                }
                catch (Exception ex)
                {

                }            
            }        
         }
}

The RunTest method does get the response XML in the responseMsge variable. How do I change the service to return that string back to the originating SoapUI?

Thanks, E

Aucun commentaire:

Enregistrer un commentaire