Solved

Create ASP.NET VB Web Service with Array

Posted on 2011-02-16
1
3,027 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!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

803 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