473,830 Members | 2,199 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.
Nov 1 '07 #1
2 2920
=?Utf-8?B?Z3Jva25yb2x s?= <gr*******@disc ussions.microso ft.comwrote in
news:25******** *************** ***********@mic rosoft.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).
Nov 1 '07 #2
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.
Nov 2 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
9706
by: Adrian Parker | last post by:
I'm using the code below in my project. When I print all of these fixed length string variables, one per line, they strings in questions do not properly pad with 0s. strQuantity prints as " 4". Six spaces than the value of intQuantity. This is correct. But all the others end up being string objects of only 6 characters long (with the exception of strTotal). The left most positions of the string object are being padded with one...
5
23680
by: ywchan | last post by:
I would like to convert a string to a fixed length e.g. if fixed length = 10 'abc' -> ' abc' 'abcdefghijklm' -> 'abcdefghij' Is there any simple function in C# can perform this operation? thanks!
2
5005
by: AlanL | last post by:
I am calling a Fortran DLL that has a declaration like: character * 260 variablename. I do not have the Fortran code. A path to a file is passed to the DLL. C# does not have a fixed character length. I can use vba or vb6 with Dim variablename as String * 260 and it works. However, I can not get this to work in C#. The DLL returns a value denoting that the file is not found. I even concatenated spaces to the string to make sure it...
3
1505
by: Ken Kast | last post by:
I'm using VBFixedString to create fixed length strings. But I find that the string will merrily allow a string of greater length to be assigned to it. Is this the way things are supposed to work? I've got a more basic question. The reason I'm doing all this is so I can pass a string buffer to an unmanaged method in a dll. It's assuming 1 byte/char. Does that mean that my fixed length should be half the size the buffer is supposed...
5
3134
by: David Garamond | last post by:
The MySQL manual recommends that we create a "fixed-length row" if possible, for speed (especially scanning speed). A fixed-length row is a row which is comprised of only fixed-length fields. A fixed-length field takes a fixed amount of bytes for storage (e.g. INT = 4 bytes, CHAR(M) = M bytes, etc). Is there a similar recommendation in PostgreSQL? I notice that most data types are stored in variable-length mode anyway (is cidr and inet...
4
2207
by: taskswap | last post by:
I'm converting an application that relies heavily on a binary network protocol. Within this protocol are a lot of byte arrays of character data, like: public unsafe struct MsgAddEntry { public byte MsgType; public uint Tag; public fixed byte ID; public fixed byte Val1;
6
1360
by: Jake Barnes | last post by:
This function has always worked for me just fine: function nl2br_js(myString){ // 02-18-06 - this function imitates the PHP command nl2br, which finds newlines in a string // and replaces them with newlines plus HTML BR tags. Is the easiest way to create the // appearance of paragraphs when people are creating web pages by typing text into a form. var regXString = "\\n"
2
5624
by: Frank Swarbrick | last post by:
I'm just learning about embedded SQL, so be gentle... My basic question is, if I use a fixed length host variable for a column defined as VARCHAR, will trailing spaces be removed (or not) upon INSERT or UPDATE of this column? I tried it, and it appears they are *not* stripped. However, the Programming Client Applications manual leads me to believe that the spaces should be stripped. A quote from that manual: -------------------------...
1
9441
by: Rick Knospler | last post by:
I am trying to convert a vb6 project to vb.net. The conversion worked for the most part except for the fixed length strings and fixed length string arrays. Bascially the vb6 programmer stored all form data in a fixed length structure that is written direct to disk. I need to load the existing files, into a fixed length structure to initialize the form data within the project. I am running into problems with statements like the...
0
9791
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10487
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10525
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9313
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6950
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5617
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3076
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.