Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / February 2007

Tip: Looking for answers? Try searching our database.

Passing Static Text Between Client and Server

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike - 21 Feb 2007 18:34 GMT
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 - 26 Feb 2007 22:15 GMT
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)
Mike - 26 Feb 2007 22:28 GMT
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

> 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)
Keith Patrick - 28 Feb 2007 17:10 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.