[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4310
  • Last Modified:

.Net C# web service with Websphere MQ adding message to a queue error in code please help

I am having a problem implementing a Websphere MQ put command into my .Net C# webservice. Here is my code and help would be great.

#region WSCF
//------------------------------------------------------------------------------
// <autogenerated code>
//     This code was generated by a tool.
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </autogenerated code>
//------------------------------------------------------------------------------
// File time 18-07-07 03:10 PM
//
// This source code was auto-generated by WsContractFirst, Version=0.7.6319.1
#endregion


namespace wsTransport
{
      using System.Diagnostics;
      using System.Web.Services;
      using System.ComponentModel;
      using System.Web.Services.Protocols;
      using System;
      using System.Xml.Serialization;
      using System.Web;
      using System.Xml;
      using System.Xml.Schema;
      using IBM.WMQ;
      
      
      /// <remarks/>
      [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "2.0.50727.42")]
      [System.Web.Services.WebServiceAttribute(Namespace="http://www.starstandards.org/webservices/2005/10/transport/bindings")]
      [System.Web.Services.WebServiceBindingAttribute(Name="starTransport", Namespace="http://www.starstandards.org/webservices/2005/10/transport/bindings")]
      public partial class WebService : System.Web.Services.WebService, IWebService
      {
            
            [System.Xml.Serialization.XmlElementAttribute(ElementName="payloadManifest")]
            public PayloadManifest payloadManifest;
            
            public WebService()
            {
            }
            
            public WebService(PayloadManifest payloadManifest)
            {
                  this.payloadManifest = payloadManifest;
            }
            
            /// <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)
                  {
                        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);

                              // Define a Websphere MQ Message

                              MQMessage xmlPayload = new MQMessage();
                              xmlPayload.WriteString(XmlDoc);

                              // 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;


                  }


            }
            
            /// <remarks/>
            [System.Web.Services.Protocols.SoapHeaderAttribute("payloadManifest")]
            [System.Web.Services.WebMethodAttribute()]
            [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://localhost/wsTransport/service/PutMessage", 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 PutMessage([System.Xml.Serialization.XmlElementAttribute(ElementName="payload")] Payload payload)
            {
                  throw new System.NotImplementedException();
            }
            
            /// <remarks/>
            [System.Web.Services.Protocols.SoapHeaderAttribute("payloadManifest", Direction=System.Web.Services.Protocols.SoapHeaderDirection.Out)]
            [System.Web.Services.WebMethodAttribute()]
            [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://localhost/wsTransport/service/PullMessage", 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")]
            [return: System.Xml.Serialization.XmlElementAttribute("payload")]
            public virtual Payload PullMessage()
            {
                  throw new System.NotImplementedException();
            }
      }
}


Here is the error information when I try and build the project

------ Build started: Project: e:\projects\transWSEngine\, Configuration: Debug .NET ------
Validating Web Site

e:\projects\transWSEngine\App_Code\STARTransport2005ArkonaMS\service.cs(76,20): error CS1513: } expected
e:\projects\transWSEngine\App_Code\STARTransport2005ArkonaMS\service.cs(102,20): error CS1519: Invalid token 'int' in class, struct, or interface member declaration
e:\projects\transWSEngine\App_Code\STARTransport2005ArkonaMS\service.cs(169,24): error CS1518: Expected class, delegate, enum, interface, or struct
e:\projects\transWSEngine\App_Code\STARTransport2005ArkonaMS\service.cs(169,110): error CS1518: Expected class, delegate, enum, interface, or struct
e:\projects\transWSEngine\App_Code\STARTransport2005ArkonaMS\service.cs(171,23): error CS1518: Expected class, delegate, enum, interface, or struct
e:\projects\transWSEngine\App_Code\STARTransport2005ArkonaMS\service.cs(179,24): error CS1518: Expected class, delegate, enum, interface, or struct
e:\projects\transWSEngine\App_Code\STARTransport2005ArkonaMS\service.cs(181,23): error CS1518: Expected class, delegate, enum, interface, or struct
e:\projects\transWSEngine\App_Code\STARTransport2005ArkonaMS\service.cs(182,9): error CS1022: Type or namespace definition, or end-of-file expected
e:\projects\transWSEngine\App_Code\STARTransport2005ArkonaMS\service.cs(168,435): error CS0106: The modifier 'virtual' is not valid for this item
e:\projects\transWSEngine\App_Code\STARTransport2005ArkonaMS\service.cs(169,108): error CS0101: The namespace 'wsTransport' already contains a definition for '?'
e:\projects\transWSEngine\App_Code\STARTransport2005ArkonaMS\service.cs(178,73): error CS0106: The modifier 'virtual' is not valid for this item
Validation Complete
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========
0
jareddraper
Asked:
jareddraper
  • 2
  • 2
1 Solution
 
davidwainwrightCommented:
I had this issue not so long since doing exactly the same thing; to fix, I manually added the wmq.dll to the project through the project explorer...

Hope this helps

Dave
0
 
jareddraperAuthor Commented:
I will give that a try thank you
0
 
jareddraperAuthor Commented:
I have the amqmdnet.dll that I added that way but I dont have a wmq.dll where would I find that dll
0
 
davidwainwrightCommented:
This thread (http://www.mqseries.net/phpBB2/viewtopic.php?t=3981&postdays=0&postorder=asc&highlight=net&start=75&sid=b55ecbf6f156aa1192be85ffadd792d3) shows a lot of the in's and outs of using the .net MQ class, but succinctly:

"You need to add a project reference to the following file:
amqmdnet.dll.

It should be in the following directory (default):
C:\Program Files\IBM\WebSphere MQ\bin\amqmdnet.dll

Then import the namespace (VB.NET / C#):
Imports IBM.WMQ
using IBM.WMQ;
..."

Dave
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now