all groups > dotnet web services > november 2007 >
You're in the

dotnet web services

group:

How to specify fixed length string parameter



How to specify fixed length string parameter groknroll
11/1/2007 6:13:00 AM
dotnet web services: 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.

Re: How to specify fixed length string parameter Spam Catcher
11/1/2007 2:57:18 PM
=?Utf-8?B?Z3Jva25yb2xs?= <groknroll@discussions.microsoft.com> wrote in
news:25F59F72-5E02-4931-8697-5C8B7C6234A4@microsoft.com:

[quoted text, click to view]

I don't think you can modify the length of a string parameter.

[quoted text, click to view]

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
RE: How to specify fixed length string parameter Arindrajit Biswas
11/2/2007 7:54:02 AM
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 InvalidOperationException(String.Format("Maximum 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.


[quoted text, click to view]
AddThis Social Bookmark Button