|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Help with .Net intergration and MQ |
« View previous topic :: View next topic » |
Author |
Message
|
rbreault |
Posted: Fri Jul 20, 2007 9:00 am Post subject: Help with .Net intergration and MQ |
|
|
Novice
Joined: 23 Jan 2007 Posts: 21
|
I have the following code that is throwing error which follow. Any help on how to solve this would be great. I would like to take an xml stream I get via web services and write it to MQ.
System.Xml.XmlElement xe = payload.content[0].Any;
// XmlDocument xmlDoc = xe.OwnerDocument;
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";
Hashtable connectionProperties = new Hashtable();
connectionProperties.Add(MQC.TRANSPORT_PROPERTY, connectionType);
connectionProperties.Add(MQC.HOST_NAME_PROPERTY, hostName);
connectionProperties.Add(MQC.CHANNEL_PROPERTY, channel);
connectionProperties.Add(MQC.PORT_PROPERTY, port);
MQQueueManager qMgr = new MQQueueManager(qManager);
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
MQQueue system_default_queue = qMgr.AccessQueue("ROB.IN.QUEUE", openOptions);
MQMessage pl = new MQMessage();
pl = xe;
MQPutMessageOptions pmo = new MQPutMessageOptions();
system_default_queue.Put(pl);
system_default_queue.Close();
qMgr.Disconnect();
}
Error message
------ 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(92,1 : error CS0029: Cannot implicitly convert type 'System.Xml.XmlElement' to 'IBM.WMQ.MQMessage'
Validation Complete
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ========== |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Jul 20, 2007 9:22 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
The error here is pl = xe.
From your code we have no way of understanding what xe is. The way you use it however it better be of MQMessage class...
Check the MQMessage interface and use it to satisfy your requirements.
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
rbreault |
Posted: Fri Jul 20, 2007 9:34 am Post subject: I made some changes but now its a different error |
|
|
Novice
Joined: 23 Jan 2007 Posts: 21
|
/// <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);
System.Xml.XmlElement xe = payload.content[0].Any;
XmlDocument xmlDoc = xe.OwnerDocument;
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";
Hashtable connectionProperties = new Hashtable();
connectionProperties.Add(MQC.TRANSPORT_PROPERTY, connectionType);
connectionProperties.Add(MQC.HOST_NAME_PROPERTY, hostName);
connectionProperties.Add(MQC.CHANNEL_PROPERTY, channel);
connectionProperties.Add(MQC.PORT_PROPERTY, port);
MQQueueManager qMgr = new MQQueueManager(qManager);
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
MQQueue system_default_queue = qMgr.AccessQueue("ROB.IN.QUEUE", openOptions);
MQMessage pl = new MQMessage();
pl = xmlDoc.OuterXml;
MQPutMessageOptions pmo = new MQPutMessageOptions();
system_default_queue.Put(pl);
system_default_queue.Close();
qMgr.Disconnect();
}
Building directory '/transWSEngine/App_Code/STARTransport2005ArkonaMS/'.
e:\projects\transWSEngine\App_Code\STARTransport2005ArkonaMS\service.cs(92,1 : error CS0029: Cannot implicitly convert type 'string' to 'IBM.WMQ.MQMessage'
Validation Complete
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========
So I guess I am confused how to get this data intop a MQMessage any help would be great. |
|
Back to top |
|
 |
Vitor |
Posted: Fri Jul 20, 2007 10:09 am Post subject: Re: I made some changes but now its a different error |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
rbreault wrote: |
So I guess I am confused how to get this data intop a MQMessage any help would be great. |
To get anything into an MQMessage you need to use a method. Check the .NET manual for details. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
rbreault |
Posted: Fri Jul 20, 2007 10:22 am Post subject: |
|
|
Novice
Joined: 23 Jan 2007 Posts: 21
|
Thank you everyone who helped point out what I was doing wrong as I just stared at the code but didn't see it. I got the code to compile now and I am getting ready to test.
[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);
//System.Xml.XmlElement xe = payload.content[0].Any;
//XmlDocument xmlDoc = xe.OwnerDocument;
System.Xml.XmlElement xe = payload.content[0].Any;
XmlDocument xmlDoc = xe.OwnerDocument;
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";
Hashtable connectionProperties = new Hashtable();
connectionProperties.Add(MQC.TRANSPORT_PROPERTY, connectionType);
connectionProperties.Add(MQC.HOST_NAME_PROPERTY, hostName);
connectionProperties.Add(MQC.CHANNEL_PROPERTY, channel);
connectionProperties.Add(MQC.PORT_PROPERTY, port);
MQQueueManager qMgr = new MQQueueManager(qManager);
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
MQQueue system_default_queue = qMgr.AccessQueue("ROB.IN.QUEUE", openOptions);
MQMessage mqmess = new MQMessage();
mqmess.WriteUTF(xmlDoc.OuterXml);
MQPutMessageOptions pmo = new MQPutMessageOptions();
system_default_queue.Put(mqmess);
system_default_queue.Close();
qMgr.Disconnect();
}
This seem to be the change I needed. I will let you know if it actually writes to the queue. |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Jul 20, 2007 10:34 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Quote: |
mqmess.WriteUTF(xmlDoc.OuterXml); |
I would not use writeUTF unless you are planning to use readUTF to read the message.
Remember that .NET native is unicode and set CCSID accordingly on the message or use the transform to ASCII string....
Note that you are not setting the format of the message either... _________________ MQ & Broker admin |
|
Back to top |
|
 |
rbreault |
Posted: Fri Jul 20, 2007 12:37 pm Post subject: |
|
|
Novice
Joined: 23 Jan 2007 Posts: 21
|
yeah I see that I am just getting this code working then I am going to clean it up and polish it. I am new so to writing code but again thank you for pointing these out to me it helps a ton so I don't put bad code out there. |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|