How to specify fixed length string parameter

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

    #1

    How to specify fixed length string parameter

    Is there a way that I can define a WebMethod with a parameter that is a fixed
    length string? I'm using VB.Net 2005 and would like to define a webmethod
    that will prevent the caller from passing a string that exceeds a certain
    fixed length. For this application if the string parameter exceeds the
    specified length it will always be an error, so I would like to put that rule
    explicitly in the contract rather than raise the error once I get the bad
    data.

    I would like to do this w/o editing the wsdl by hand.

    Thanks in advance for any help.
  • Spam Catcher

    #2
    Re: How to specify fixed length string parameter

    =?Utf-8?B?Z3Jva25yb2x s?= <groknroll@disc ussions.microso ft.comwrote in
    news:25F59F72-5E02-4931-8697-5C8B7C6234A4@mi crosoft.com:
    Is there a way that I can define a WebMethod with a parameter that is
    a fixed length string?
    I don't think you can modify the length of a string parameter.
    I'm using VB.Net 2005 and would like to define
    a webmethod that will prevent the caller from passing a string that
    exceeds a certain fixed length. For this application if the string
    parameter exceeds the specified length it will always be an error, so
    I would like to put that rule explicitly in the contract rather than
    raise the error once I get the bad data.
    That's what exceptions are for... It would be nice to declare it up front,
    but it's not like the client would respect it anyways (i.e. say you have a
    ..NET Client, the client won't be able to enforce the string length in the
    development GUI).

    Comment

    • =?Utf-8?B?QXJpbmRyYWppdCBCaXN3YXM=?=

      #3
      RE: How to specify fixed length string parameter

      You can achieve this bit indirect way. What you have to do is instead of
      using String class, create a custom class and use that. And you can force
      length check in your class.
      C# sample code:

      [Serializable]
      MyString
      {
      const int fixLngeth = 30;

      private String myString;
      public String MyString
      {
      get{ return this.myString;}
      set{
      if(value.length fixLength)
      throw new InvalidOperatio nException(Stri ng.Format("Maxi mum length
      of the message is {0}", fixLength)) ;

      this.myString = value;}
      }

      }

      This will not stop user from assigning any value on client side, if they use
      WSDL generated code. But as soon as the invoke method in server, it will give
      serialisation failure.


      "groknroll" wrote:
      Is there a way that I can define a WebMethod with a parameter that is a fixed
      length string? I'm using VB.Net 2005 and would like to define a webmethod
      that will prevent the caller from passing a string that exceeds a certain
      fixed length. For this application if the string parameter exceeds the
      specified length it will always be an error, so I would like to put that rule
      explicitly in the contract rather than raise the error once I get the bad
      data.
      >
      I would like to do this w/o editing the wsdl by hand.
      >
      Thanks in advance for any help.

      Comment

      Working...