ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » .Net (c#) Serialization examples

Post new topic  Reply to topic
 .Net (c#) Serialization examples « View previous topic :: View next topic » 
Author Message
weavedd
PostPosted: Mon May 12, 2014 7:05 am    Post subject: .Net (c#) Serialization examples Reply with quote

Newbie

Joined: 10 Oct 2013
Posts: 5

Adding logging around my message flow and I would like to capture and log the:
1) input message
2) web service request
3) web service response

I would like to convert these ESQL compute notes to .Net compute nodes, but am not having any success finding ASBITSTREAM .Net (c#) examples that I can get to work. Can someone point me in the right direction or provide a link to .Net ASBITSTREAM examples?


Code:
CREATE COMPUTE MODULE LogMessage_SaveMrmMessage
   CREATE FUNCTION Main() RETURNS BOOLEAN
   BEGIN
      --MRM (Cobol copybook defined message)
      SET OutputRoot = InputRoot;
      DECLARE msgBlob BLOB ASBITSTREAM(InputRoot, InputRoot.Properties.Encoding, InputRoot.Properties.CodedCharSetId );
        DECLARE msgChar CHAR CAST(msgBlob AS CHAR CCSID InputRoot.Properties.CodedCharSetId);
        set msgChar = SUBSTRING(msgChar FROM 365);            
      SET Environment.DFDL.LogMessage.QueueMessage = msgChar;      
      RETURN TRUE;
   END;
END MODULE;

CREATE COMPUTE MODULE LogMessage_SaveXmlRequest
   CREATE FUNCTION Main() RETURNS BOOLEAN
   BEGIN
      --XMLNSC (mapped copybook to web service request)
      SET OutputRoot = InputRoot;
      DECLARE msgBlob BLOB ASBITSTREAM(InputRoot.XMLNSC, InputRoot.Properties.Encoding, InputRoot.Properties.CodedCharSetId );
        DECLARE msgChar CHAR CAST(msgBlob AS CHAR CCSID InputRoot.Properties.CodedCharSetId);
      SET Environment.DFDL.LogMessage.RequestText = msgChar;
      RETURN TRUE;
   END;
END MODULE;

CREATE COMPUTE MODULE LogMessage_SaveXmlResponse
   CREATE FUNCTION Main() RETURNS BOOLEAN
   BEGIN
      --XMLNSC (response object from web service request)
      DECLARE msgBlob BLOB ASBITSTREAM(InputRoot.XMLNSC, InputRoot.Properties.Encoding, InputRoot.Properties.CodedCharSetId );
        DECLARE msgChar CHAR CAST(msgBlob AS CHAR CCSID InputRoot.Properties.CodedCharSetId);
      SET Environment.DFDL.LogMessage.ResponseText = msgChar;
      RETURN TRUE;
   END;
END MODULE;
Back to top
View user's profile Send private message
smdavies99
PostPosted: Mon May 12, 2014 11:19 am    Post subject: Re: .Net (c#) Serialization examples Reply with quote

Jedi Council

Joined: 10 Feb 2003
Posts: 6076
Location: Somewhere over the Rainbow this side of Never-never land.

weavedd wrote:
Adding logging around my message flow and I would like to capture and log the:
1) input message
2) web service request
3) web service response


Ok. Fair enough. Most of us here do that all the time.

Why are you trying to change the ESQL to .Net? Is this a learning exercise or for real?

Turning to your point about logging things in your flow.

I really hope you don't want to do all of this by writing to files from .NET code

It is fair to say most of us here do this in a very, very different way from that.

In my case, I have invested the time to develop a common logging and error handling subsystem. This means that I can plug the sub-flows into my main flow and all of this is handled for me, quickly, reliably and easily.

If I think back to 2002 and MQSI V2.0.2, I tried to do the same as you and failed miserably.

Then I went back to first principle and started to use the power of Broker to its best advantage.
_________________
WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995

Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions.
Back to top
View user's profile Send private message
weavedd
PostPosted: Mon May 12, 2014 12:34 pm    Post subject: Reply with quote

Newbie

Joined: 10 Oct 2013
Posts: 5

Solved my problem. When I moved my message from the Environment domain to the the InputRoot I was able to serialize both an XML and a MRM


// Serialized example of log message request - XMLNSC
var returnResponse = string.Empty;
var error = false;
try
{
var aRequest = inputRoot["XMLNSC"]["LogMessage"]["RequestText"].AsBitStream(NBBitStreamControl.FolderBitStream);
var returnResponse = Encoding.UTF8.GetString(aRequest);
}
catch (Exception ex)
{
returnResponse = "Error serializing request";
error = true;
}


// Serialized example of MRM
try
{
var aMessage = inputRoot["MRM"].AsBitStream();
var returnResponse = Encoding.UTF8.GetString(aMessage);
}
catch (Exception ex)
{
error = true;
}
Back to top
View user's profile Send private message
kimbert
PostPosted: Mon May 12, 2014 1:39 pm    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

Any reason why you are using MRM and not DFDL for this?
Any reason why you need *either* of those domains for logging? Do you have a particular log format that you are writing to?
And finally, why use AsBitstream when you could just propagate the tree to an output node and get the message automatically serialized for you? ( it would do exactly the same, because you are not supplying any parameters to AsBitstream ).
_________________
Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too.
Back to top
View user's profile Send private message
weavedd
PostPosted: Tue May 13, 2014 5:15 am    Post subject: Reply with quote

Newbie

Joined: 10 Oct 2013
Posts: 5

Good questions kimbert. Yes, I should have used DFDL for this instead of MRM. I have no reason for using MRM other than that's how the consultant that did our training showed us how to import Cobol copybooks. I have been migrating those to DFDL once I found that I import copybooks through that domain, but had not gotten around to this one.

The reason I was using asbitstream was to serialize the request and response inside a logging message that I'm building when errors occur. When an error occurs I place this message to a log queue that gets written to a database for users to determine if they want to reprocess the message or not.

<logentry>
<user>Test</user>
<logdatetime>5/13/2014 8:00:00AM</logdatetime>
<loglevel>99</loglevel>
<queuename>APP.OBJECT.ACTION</queuename>
<messageflow>Flow Name</messageflow>
<acknowledged>false</acknowledged>
<queuemessage>xferInv ABC 10 Loc1 Loc2</queuemessage>
<request><xml><method>xferInv</method><item>ABC</item><qty>10</qty>fromLoc>Loc1</fromLoc><toLoc>Loc2</toLoc></logentry></xml></request>
<response><xml><message>Item not setup</message><error>true</error></xml></response>
</logentry>

kimber or smdavies99 if you can point me to resources or patterns that handle logging and reprocessing of failed message more effictively I'd appreciate it.
Back to top
View user's profile Send private message
kimbert
PostPosted: Tue May 13, 2014 11:26 am    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

It's hard to advise on logging/reprocessing without knowing a lot about your requirements and environment.
I will point out one thing, though. Your 'working' .NET code contains a serious defect. It is assuming the the result of AsBitstream() is a valid UTF-8 stream. That's not true in general ( a BLOB contains bytes, not UTF-8 characters ). Even if it happens to be true today in your organisation, you should not bake that assumption into your logging code.
_________________
Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too.
Back to top
View user's profile Send private message
weavedd
PostPosted: Tue May 13, 2014 11:49 am    Post subject: Reply with quote

Newbie

Joined: 10 Oct 2013
Posts: 5

Fair enough. So back to my original question do you have any working examples or documentation that isn't a simple .Net class outline?
Back to top
View user's profile Send private message
mqjeff
PostPosted: Tue May 13, 2014 12:03 pm    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

Why do you want to do this in code, rather than using record and replay?
\
Back to top
View user's profile Send private message
Vitor
PostPosted: Tue May 13, 2014 12:07 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

weavedd wrote:
So back to my original question do you have any working examples or documentation that isn't a simple .Net class outline?


While I hate to answer a question with a question, why are you doing this with code? In the "what's the requirement?" sense. My .NET is only slightly better than my Java (i.e. ghastly) but it looks like you're just trying to capture the message tree payload data. If the only log points are on input, on web service request and on web service response, why not configure a monitoring profile to capture that data as it passes the relevant terminals? Granted you'd need to configure multiple points (unless you can get clever with naming standards) but that's no worse than inserting code at all the needed points.

While this means you need a fairly trival piece of code / message flow to process the events, the advantage is that you can use any number of trival pieces of code with various subscriptions to give as many people the information as you need.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
weavedd
PostPosted: Tue May 13, 2014 12:23 pm    Post subject: Reply with quote

Newbie

Joined: 10 Oct 2013
Posts: 5

Thanks Vitor and mqjeff. I was unaware of both of these capabilities and I will pursue these options instead.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » .Net (c#) Serialization examples
Jump to:  



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
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.