?
Solved

XML C# stream to String writing to Websphere MQ

Posted on 2007-07-19
9
Medium Priority
?
7,994 Views
Last Modified: 2013-11-15
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.
0
Comment
Question by:jareddraper
  • 4
  • 4
9 Comments
 
LVL 9

Expert Comment

by:traxion
ID: 19526130
Try changing xmlDoc in the second section to objxmlDoc and see what happens.  
0
 
LVL 19

Expert Comment

by:drichards
ID: 19526217
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
 
LVL 19

Expert Comment

by:drichards
ID: 19526254
Maybe you meant something like:

    xmlPayload.WriteString(xmlDoc.OuterXml);
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:jareddraper
ID: 19526338
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
 

Author Comment

by:jareddraper
ID: 19526426
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
 
LVL 19

Expert Comment

by:drichards
ID: 19526464
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
 

Author Comment

by:jareddraper
ID: 19526522
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
 
LVL 19

Accepted Solution

by:
drichards earned 1500 total points
ID: 19526660
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
 

Author Comment

by:jareddraper
ID: 19527033
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Rules and regulations were devised in order to maintain the integrity of a system. However, interpretation of rules can be quite tricky.
Here in this article, you will get a step by step guidance on how to restore an Exchange database to a recovery database. Get a brief on Recovery Database and how it can be used to restore Exchange database in this section!
Viewers will learn how to use the Hootsuite Dashboard.
XMind Plus helps organize all details/aspects of any project from large to small in an orderly and concise manner. If you are working on a complex project, use this micro tutorial to show you how to make a basic flow chart. The software is free when…
Suggested Courses

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question