XML C# stream to String writing to Websphere MQ

ok question I have is how do I get this stream that I write to a string later in my code.

      // Here is the Code that reads the XML Payload Stream and Validates it to the correct Schema before sending the message forward.

                  System.Xml.XmlElement xe = payload.content[0].Any;
                  XmlDocument xmlDoc = xe.OwnerDocument;
                  xmlDoc.Schemas.Add(null, "http://localhost/wsTransport/ProcessCreditContract.xsd");
                  xmlDoc.Validate(delegate(object sender, ValidationEventArgs vargs)
                  {
                        Console.WriteLine("{0}: {1}", vargs.Severity, vargs.Message);
                  }, xe);

When I grab it here I can validate the xml against a .xsd file without issue. Now I want to take that same xml

and write it to a Websphere MQ Queue

something like this

MQMessage xmlPayload = new MQMessage();
                    XmlDocument xmlDoc = xe.OwnerDocument;
                    xmlPayload.WriteString(xmlPayload);

but I get the following error

------ Build started: Project: e:\projects\transWSEngine\, Configuration: Debug .NET ------
Validating Web Site
Building directory '/transWSEngine/App_Code/STARTransport2005ArkonaMS/'.

e:\projects\transWSEngine\App_Code\STARTransport2005ArkonaMS\service.cs(129,33): error CS0136: A local variable named 'xmlDoc' cannot be declared in this scope because it would give a different meaning to 'xmlDoc', which is already used in a 'parent or current' scope to denote something else
e:\projects\transWSEngine\App_Code\STARTransport2005ArkonaMS\service.cs(130,21): error CS1502: The best overloaded method match for 'IBM.WMQ.MQMessage.WriteString(string)' has some invalid arguments
e:\projects\transWSEngine\App_Code\STARTransport2005ArkonaMS\service.cs(130,44): error CS1503: Argument '1': cannot convert from 'IBM.WMQ.MQMessage' to 'string'
Validation Complete
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========

any help would be great as I am so close to getting this project finished just need to get over this last step.
jareddraperAsked:
Who is Participating?
 
drichardsConnect With a Mentor Commented:
Other than the Windows event log, I am not sure.  I deal with development servers where I can just trace through the code, not production ones, so I am not sure of all the available diagnostics.

IS the XML doc correctly populated?  The simplest cause for the problem is that the doc is blank.
0
 
traxionCommented:
Try changing xmlDoc in the second section to objxmlDoc and see what happens.  
0
 
drichardsCommented:
Two things.

1) The MQMessage chunk of code does not even use xmlDoc.  I assume you meant to extract the doc text and send IT on the MQ.

2) Does the MQMessage chunk of code come right after the XML validation code?  If so, you already have declared and set xmlDoc, so you do not need to do so again.  You should be able to just do:

                    MQMessage xmlPayload = new MQMessage();
                    ... use xmlDoc already declared...
                    xmlPayload.WriteString(xmlPayload);

And as to the other two errors, they are saying that MQMessage.WriteString needs a string parameter.  You are trying to write the MQ to itself in the code you show here.  As I said in (1), I assume you want to extract the XML text and send it to the MQ.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
drichardsCommented:
Maybe you meant something like:

    xmlPayload.WriteString(xmlDoc.OuterXml);
0
 
jareddraperAuthor Commented:
I will give this a try

MQMessage xmlPayload = new MQMessage();
                    ... use xmlDoc already declared...
                    xmlPayload.WriteString(xmlPayload);

you are correct it is right after I validate the message
0
 
jareddraperAuthor Commented:
ok I was able to compile finally but never got a message to the queue. Here is the complete snipet of code for what I am doing.


            /// <remarks/>
            [System.Web.Services.Protocols.SoapHeaderAttribute("payloadManifest", Direction=System.Web.Services.Protocols.SoapHeaderDirection.InOut)]
            [System.Web.Services.WebMethodAttribute()]
            [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://localhost/wsTransport/service/ProcessMessage", RequestNamespace="http://www.starstandards.org/webservices/2005/10/transport", ResponseNamespace="http://www.starstandards.org/webservices/2005/10/transport", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped, Binding="starTransport")]
            public virtual void ProcessMessage([System.Xml.Serialization.XmlElementAttribute(ElementName="payload")] ref Payload payload)
            {
                  // Here is the Code that reads the XML Payload Stream and Validates it to the correct Schema before sending the message forward.

                  System.Xml.XmlElement xe = payload.content[0].Any;
                  XmlDocument xmlDoc = xe.OwnerDocument;
                  xmlDoc.Schemas.Add(null, "http://localhost/wsTransport/ProcessCreditContract.xsd");
                  xmlDoc.Validate(delegate(object sender, ValidationEventArgs vargs)
                  {
                        Console.WriteLine("{0}: {1}", vargs.Severity, vargs.Message);
                  }, xe);


            // Websphere MQ Series Connection to dump payload to queue


            const String connectionType = MQC.TRANSPORT_MQSERIES_CLIENT;
            const String qManager = "ARKDEV.QUEUE.MANAGER";
            const String hostName = "arkdev.arkona.com";
            const String channel = "SYSTEM.ADMIN.SVRCONN";
            const String port = "1414";

            // Initialise the connection properties for the type requested

          //  Static Hashtable init(String connectionType);
          //  {
         //   init(connectionType);

                Hashtable connectionProperties = new Hashtable();

                // Add the connection type

                connectionProperties.Add(MQC.TRANSPORT_PROPERTY, connectionType);

                // Setup the rest of the connection properties, based on connection type requested

                switch(connectionType)
                {
                    case MQC.TRANSPORT_MQSERIES_BINDINGS:
                        break;
                    case MQC.TRANSPORT_MQSERIES_CLIENT:
                        connectionProperties.Add(MQC.HOST_NAME_PROPERTY, hostName);
                        connectionProperties.Add(MQC.CHANNEL_PROPERTY, channel);
                        connectionProperties.Add(MQC.PORT_PROPERTY, port);
                        break;
                }

            //    return connectionProperties;
           // }

            // The Main Entry point for Websphere MQ

          //  Static int Main(String[] args);
           // {
                try
                {
             //       Hashtable connectionProperties; //= init(connectionType);

                    // Create a connection to the Queue manager using the connection properties just defined

                    MQQueueManager qMgr = new MQQueueManager(qManager, connectionProperties);

                    // Set up the options on the queue we wish to open

                    int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;

                    // Now we specify the queue that we wish to open

                    MQQueue wsTransport_in_queue =
                      qMgr.AccessQueue("ROB.IN.QUEUE", openOptions);


                    MQMessage xmlPayload = new MQMessage();
                    xmlPayload.WriteString(xmlDoc.OuterXml);

                    //MQMessage hello = new MQMessage();
                    //hello.WriteUTF("I hate this sometimes coding gives me bad dreams");

             

                    // Specify the message options

                    MQPutMessageOptions pmo = new MQPutMessageOptions(); // Accept the default

                    // Put the Message on the Queue

                    wsTransport_in_queue.Put(xmlPayload, pmo);

                    // Close the Queue

                    wsTransport_in_queue.Close();

                    // Disconnect from Queue Manager

                    qMgr.Disconnect();
                }

                // If an error has occurred in the above, try to identify what went wrong.

                // Was it a Websphere MQ error?

                catch (MQException ex)
                {
                    Console.WriteLine("A Websphere MQ error occurred: {0}", ex.ToString());
                }

                catch (SystemException ex)
                {
                    Console.WriteLine("A system error occurred: {0}", ex.ToString());
                }

            //    return 0;


           // }


}
0
 
drichardsCommented:
My only suggestion here is to make sure that at the line:

                    xmlPayload.WriteString(xmlDoc.OuterXml);

you see OuterXml has the document contents as you expect.  If that is the case then you will need additional help because I don't know about the IBM MQ.
0
 
jareddraperAuthor Commented:
ok thank you for pointing me in that direction. One simple question I am used to apache does IIS/ASP.NET have a log file that I could read to see if there are errors happening?
0
 
jareddraperAuthor Commented:
yeah I am going through it all now. I am not sure that the document was getting there so I am trying to write to the queue with no validation first to make sure the data I send is even getting there.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.