locked
Global variables web services? RRS feed

  • Question

  • User30110692 posted

    My question is simples... i need to use global variables in web services how can i use?

    int a;

    [Web method]

    my function()

    {

    a = 3;

    }

    [Web method]

    anotherfunction()

    {

    int g = a;

    }

    the problem is.. when i invoke anotherfunction the variable "a" is null.

    How can i resolve this?

    Wednesday, February 17, 2010 12:16 PM

Answers

  • User197322208 posted

    http://msdn.microsoft.com/en-us/library/system.web.services.webservice.application.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 17, 2010 4:37 PM
  • User197322208 posted

    In the

    http://msdn.microsoft.com/en-us/library/system.web.services.webservice.application.aspx

    The example is with "int"

    Replaceint with int[][]

    if (Application["HitCounter"] == null) {

              Application["HitCounter"] = new int[40][70];
    }
    else {


    {


    int[][] a = (int[][]) Application["HitCounter"]) ;
    //do your job with a
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 17, 2010 5:12 PM

All replies

  • User197322208 posted

    http://msdn.microsoft.com/en-us/library/system.web.services.webservice.application.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 17, 2010 4:37 PM
  • User30110692 posted

    Hello ignatandre,

    the problem is i´m using as global variable a matrix, like this:

    public static int[][] myMatrix;


    How can i resolve this, if it is possible?

    Wednesday, February 17, 2010 5:02 PM
  • User197322208 posted

    In the

    http://msdn.microsoft.com/en-us/library/system.web.services.webservice.application.aspx

    The example is with "int"

    Replaceint with int[][]

    if (Application["HitCounter"] == null) {

              Application["HitCounter"] = new int[40][70];
    }
    else {


    {


    int[][] a = (int[][]) Application["HitCounter"]) ;
    //do your job with a
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 17, 2010 5:12 PM
  • User-1451363702 posted

    This is an old questions, but I will try to answer as it may help somebody else ;-)

    This can be achieved by just asking WCF to run a single instance of your service. Add the following line (decorator) to the definition of your class
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]

    If you want the behavior only for the same session but not across clients then you can mark it as per session by the following service behavior
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]

    The other option is per call which is the default option.
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]

    Saturday, April 20, 2013 4:20 AM