Passing Static Text Between Client and Server

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?TWlrZQ==?=

    #1

    Passing Static Text Between Client and Server

    I have a list of static text that I want the client and server to be able to
    share such that I don't have to hard-code the text on both sides. The client
    communicates with the server via web services.

    How do I set this up so that both sides can simply refer to the the same text?

    I tried a struct with static properties, it works on the server but there is
    no reference on the client side to the static properties. There's a
    reference to the struct but not the properties.

    Ex:
    public struct StatusType
    {
    public static string Accepted
    {
    get { return "Accepted"; }
    }
    public static string Rejected
    {
    get { return "Rejected"; }
    }
    public static string OnHold
    {
    get { return "On Hold"; }
    }
    }

    It works when I do something similar with enums, but I need to refer to the
    actual text such as "On Hold".

    TIA
  • Keith Patrick

    #2
    Re: Passing Static Text Between Client and Server

    You can put the struct into a separate project & have both client and server
    each reference the common assembly.
    Also, the normal practice for declaring constants is to go ahead and use
    fields (one of the few places where public fields are OK):
    public const String Accepted (const is implied to be static)



    Comment

    • =?Utf-8?B?TWlrZQ==?=

      #3
      Re: Passing Static Text Between Client and Server

      So for your second option, would I have to put the public const String
      Accepted in a class that is return by some method or can I put it in its own
      class? If it's in its own class, how will wsdl know to include it in the
      proxy? Or do all public const's automatically get included?

      Thank you


      "Keith Patrick" wrote:
      You can put the struct into a separate project & have both client and server
      each reference the common assembly.
      Also, the normal practice for declaring constants is to go ahead and use
      fields (one of the few places where public fields are OK):
      public const String Accepted (const is implied to be static)
      >
      >
      >
      >

      Comment

      • Keith Patrick

        #4
        Re: Passing Static Text Between Client and Server

        If you're encapsulating your constants as a struct, then merely referencing
        it in your project and using it in your web method will tell the WSDL to
        define it. Your web client might try to make a proxy version of your struct
        in the References.cs file, so you have to make sure you mark your struct
        with XmlRoot("your web service's namespace") so that the code generation
        tool uses the one that is already referenced by both projects instead of
        creating a new one for the client



        Comment

        Working...