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 / ASP.NET / Web Services / February 2005

Tip: Looking for answers? Try searching our database.

How to specify the input data bounds in web service?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Yolande - 21 Feb 2005 21:07 GMT
Hi there,

I have a C# web service and I want to specify the lower bound and upper
bound of input value. e.g.  [WebMethod] public long MilesToKilometers(long
lngMiles). I want the input value for lngMiles is within [0,100]. I expect
that there are some properties can be set before actually executing the
method. I don't want to validate the value in the method. Is there any help?

If I cannot validate the value in the C# code (except within the method),
can I do it using schema in WSDL? How? Thank you very much.

Yolande

Trevor Pinkney - 21 Feb 2005 21:29 GMT
Hello Yolande,

You need to manually check if lngMiles is within range and throw a SoapException
if there is a problem.

if(lngMiles<0 || lngMiles>100)
{
  SoapException se = new SoapException("Out of Range.  Miles must be between
0 and 100",...);
  se.Detail = "<Error><Code>100</Code><Description>Out of Range.  Miles
must be between 0 and 100</Description></Error>";
  throw se;
}

-Trevor

> Hi there,
>
[quoted text clipped - 9 lines]
>
> Yolande
erymuzuan - 21 Feb 2005 23:38 GMT
Remember that WSDL is your contract, and if you want this in you your
contract then you should say so. If you're not keen in writing WSDL
first, get Chritian weyer Contract first add -in.
or you can save your WSDL(auto gen.) go to to types where it says

<xs:element name="lngMiles" type="xsd:int"/>

change this to

<xs:element name="lngMiles">
    <xs:simpleType>
        <xs:restriction base="xs:int">
            <xs:minInclusive value="0"/>
            <xs:maxInclusive value="100"/>
        </xs:restriction>
    </xs:simpleType>
</xs:element>

then save it in your web dir. Disable web services documentation in
web.config. let your user use this new wsdl file.

for the validation you can use SoapExtension, see this article
http://msdn.microsoft.com/msdnmag/issues/02/11/XMLFiles/default.aspx

regards
erymuzuan mustapa

> Hello Yolande,
>
[quoted text clipped - 25 lines]
>>
>> Yolande

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.