Accessing a static method from Orchestration Expression

Answered Accessing a static method from Orchestration Expression

  • Thursday, January 28, 2010 10:48 AM
     
     
    Hi all
    How can I access the method getXmlDocument
    from a Orchestration Expression

    I tried something like this

    var = new %namespace%.Invoice_Decoder(); //Note Var is type %namespace.Invoice_Decoder%
    varGet = var.getXmlDocument(msgCoded);  // varGet is type System.Xml.Document

    The error message below is showing getXmlDocument %Error%(msgCoded) between getXmlDocument and (msgCoded)

    I am getting an error 
    static member cannot be accessed with an instance reference qualify it with a type name instead


     [Serializable]
    	public class Invoice_Decoder
        
    
        {
            public Invoice_Decoder()
    		{
    			//
    			// TODO: Add constructor logic here
    			//
    		}	
    
    
            public static XmlDocument getXmlDocument(XLANGMessage baseCodeInvMessage )
    		{
    
           blalba
                     }


    AKE

All Replies

  • Thursday, January 28, 2010 10:52 AM
    Answerer
     
     
    You can not access a static method from an instance. Your code should read:

    varGet = %namespace%.Invoice_Decoder.getXmlDocument(msgCoded);
    • Marked As Answer by Akaschmid Thursday, January 28, 2010 11:03 AM
    • Unmarked As Answer by Akaschmid Thursday, January 28, 2010 2:24 PM
    •  
  • Thursday, January 28, 2010 10:59 AM
    Moderator
     
     
    Hi AKE,

    I assume you want to call a custom .NET component. Here is an example of an implementation, which could be usefull for you to review: http://www.codeproject.com/KB/biztalk/CallCustomDllBiztalk2006.aspx.

    Regards,

    Steef-Jan Wiggers (http://soa-thoughts.blogspot.com/)
    BizTalk Server
    • Marked As Answer by Akaschmid Thursday, January 28, 2010 11:03 AM
    • Unmarked As Answer by Akaschmid Thursday, January 28, 2010 2:24 PM
    •  
  • Thursday, January 28, 2010 11:03 AM
     
     
    HI

    Thanks for speedy response

    :-)

    AKE
  • Thursday, January 28, 2010 2:30 PM
     
     
    Hi all

    I tried all the solution above ..
    Non of them worked

    I was getting the error.. 

    must be a type : when I use: varGet = %namespace%.Invoice_Decoder.getXmlDocument(msgCoded);

    getXmlDocument "must be a type"

    As soon as I remove the static type.. it works with out problem..

    But I have a need to use the static.

    Thanks in Advance

    AKE
  • Thursday, January 28, 2010 2:36 PM
    Moderator
     
     
    Hi AKE,

    Is there a particular reason you need to use static. Maybe you could review this post: http://seroter.wordpress.com/2007/08/17/behavior-of-static-objects-in-biztalk-runtime/.

    Regards,

    Steef-Jan
    BizTalk Server
  • Thursday, January 28, 2010 2:40 PM
     
     
    Hi Jan

    Need to make sure that is only 1 instance of the object 
    is alive during a transaction

    How save is using  just public XmlDocumet?

    Regards

    AKE
  • Thursday, January 28, 2010 2:43 PM
    Moderator
     
     
  • Thursday, January 28, 2010 3:14 PM
     
     Answered
    Hi AKE,

    As suggested by Greg, using the class name should work to call a static method of class from Orchestration expression shape.

    varGet = %namespace%.Invoice_Decoder.getXmlDocument(msgCoded);

    I have called static methods of external assemblies it in many projects without any issue.  Are you getting error at design time or run time?

    If your class is a utility class with only static methods, then change the class also to static and then you do not need to use [Serializable] for a static class.  Make sure to Gac the assembly and restart host instance before testing it (you may not have restarted host insatce in your last test).


    Regards,

    Tariq Majeed
    Please mark it as answer if it helps
    • Marked As Answer by Akaschmid Tuesday, February 02, 2010 6:35 AM
    •  
  • Thursday, January 28, 2010 6:38 PM
     
     

    As Tariq mentioned, you just need to make sure that your latest changes are reflected ..During development, you can ensure this by writing some information messages into event log from your static method.

    HTH,


    Please mark it as answer by clicking on "Propose As Answer", if it helps
  • Thursday, January 28, 2010 8:40 PM
     
     


    If your class is a utility class with only static methods, then change the class also to static and then you do not need to use [Serializable] for a static class.  Make sure to Gac the assembly and restart host instance before testing it (you may not have restarted host insatce in your last test).
    Hi Tariq .. I think you made a point.. here.. class with only static methods, need to be static class also.. 
    I will try this tomorrow morning and give you the feedback
    Kind regards

    AKE
  • Friday, January 29, 2010 9:03 AM
     
     

    Hi,

    The methods in a static class need to be reentrant and threadsafe, because many orchestration instances could simultainously call the same method. Hence better way is to go for a singleton class instead of a static class. When you call methods of a singleton class separate stack frame is created for each such call and hence no complications.


    Please mark as answer if this helps you. Thanks and warm regards Ambar Ray EAI Architect - Microsoft Technologies
  • Tuesday, February 02, 2010 6:37 AM
     
     
    Hi all
    Thanks for your effort..

    The static class  solved my problem for now..
    Later I will have a look at the constraints as a result of calling a static method in an Orch..

    Best
    Regards

    AKE