Solved

Create ASP.NET VB Web Service with Array

Posted on 2011-02-16
1
2,921 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now