Solved

Create ASP.NET VB Web Service with Array

Posted on 2011-02-16
1
3,079 Views
Last Modified: 2013-11-18
Hi all, I'm new at the web service development thing...and hopefully someone can help me design a basic web service that does the following:

Receives three pieces of data:

- OrderID (Int32)
- OrderStatus (String, 1)
- OrderDate (DateTime)

Now, if the client was connecting to the web service and giving me one record at a time with a response, it would be a no-brainer on how to create this...

Basically, what I need to do is accept multiple records at once...Is an array the best way to accept?

Then, if all succeeds, I send them back a message or code that says the import was successful.  If it failed, (or a record or two failed), I send them back an array or something that tells them which orders failed to be accepted.

Any code examples in VB would be greatly appreciated.
0
Comment
Question by:ripple123
1 Comment
 
LVL 3

Accepted Solution

by:
mohanupadhyay earned 500 total points
ID: 34913766
File => New Project => VB Web Service Application

add following function into service1.asmx file

<WebMethod()> _
    Public Function ImportOrders(ByVal orderid As Integer()) As Integer()
        Dim failed As Integer()
        Dim i As Integer, k As Integer

        k = 0
        For i = 0 To orderid.Length - 1
            If orderid(i) < 1 Or orderid(i) > 10 Then
                ReDim failed(k + 1)
                failed(k) = orderid(i)
            End If
        Next
        Return failed
    End Function

'===========================================================================

Add a web form and add the following code on page load event

Dim obj As New Service1
        Dim orderids As Integer() = {2, 11, 1, 10}
        Dim failed As Integer()
        failed = obj.ImportOrders(orderids)

        Dim i As Integer
        For i = 0 To failed.Length - 1
            Response.Write(failed(i).ToString() + "<br>")
        Next

'===================================================================


0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question