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.