Solved

Web Services -- Returning custom XML through a <WebMethod()> ?

Posted on 2004-04-19
10
849 Views
Last Modified: 2008-02-26
Hello,

I'm trying to write a simple ASP.NET web service, written in VB.NET using VS.Net 2003. Here's the code:

----------

<WebMethod()> _
    Public Function Authenticate_User(ByVal Username As String, ByVal Password As String, ByVal Error_URL As String) As ????????

             ' Code in here

    End Function

----------

Now, what I am trying to do is to return some XML BACK through the method that was invoked. So, for example, calling:

http://[server]/security.asmx/Authenticate_User?username=xxx&password=xxx will return something like:

<STATUS>0</STATUS>
<MESSAGE>Message in here</MESSAGE>

However, in the above code, where the WebMethod is declared "AS ?????", I don't know what to use. If I use:

Public Function Authenticate_User(ByVal Username As String, ByVal Password As String, ByVal Error_URL As String) *** AS STRING ***

the resulting XML is not proper, in the sense that you simply get the standard web service XML returned, then my XML, enclosed within the <STRING></STRING> tags.

Is there a way to output normal XML? By using a proper declaration in the <WebMethod()> statement?

Thanks,

ICX.
0
Comment
Question by:icx
  • 5
  • 5
10 Comments
 
LVL 1

Author Comment

by:icx
ID: 10858438
Just thought ---

It'd be better if I could use a DataSet and return that through the web service. But all the examples I've been able to find were geared towards return a dataset with results from SQL or similar. If DS are a possibility, how can one add 'custom' records to a DataSet object? EG.

DataSet.Add("FIELDNAME","VALUE")

Thanks
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 10858744
yes you can send dataset object through the web service
after receiving  the ds in the client
you can modify the ds.tables collection as a normal datatable object

i.e.
Dim dr as datarow = ds.tables(0).newrow()
dr(0) = id
dr(1) = text
ds.tables(0).rows.add ( dr )

B..M
0
 
LVL 1

Author Comment

by:icx
ID: 10858824
OK,

Let's say then that I wanted to return:

<STATUS>0</STATUS> as XML to the client, as well as:
<MESSAGE>Message here</MESSAGE>

Would I use:

dr(0) = 0
dr(1) = "Message here"

ds.tables(0).rows.add(dr)

What would the resulting output from the web service look like, assuming we use:

RETURN DS() in the WebMethod() ?

Thanks
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 10858896
sorry, but i didn't read you question carefully
i was answering that it is possible to return dataste from web service
about your problem

have you tried this

create
public class StatusMessages
 Dim status as string
 Dim message as string
End class

and you webmethod to return an object of StatusMessages()
in the client you can modify this array

as for the dataset it could be made but you won't receive the wanted structure at all

HTH
B..M
0
 
LVL 1

Author Comment

by:icx
ID: 10859071
Ok,

But what should I declare the web method AS?

Eg.

<WebMethod()>
Public Function TEST_FUNCTION() AS ??????????

End Function

Thanks
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 28

Expert Comment

by:mmarinov
ID: 10859151
<WebMethod()>
Public Function TEST_FUNCTION() AS StatusMessages()

B..M
0
 
LVL 1

Author Comment

by:icx
ID: 10859185
Okeydokey.

Bear with me here.

I've now done this.

What code do I use in the web method itself?

I tried to use:

Dim SM as New StatusMessages
SM.Status = 0
SM.Message = "This message"

Return SM

But in VS.NET, Whenever I type SM., I only get "GetType" as an option, not the other entries we made.

Any ideas what's up?

Thanks.
0
 
LVL 28

Accepted Solution

by:
mmarinov earned 120 total points
ID: 10859260
bad begining of the week :-(
sorry, but it is normal if you've written down as i've posted
public class StatusMessages
 Dim status as string
 Dim message as string
End class

the correct code is
public class StatusMessages
 public status as string
 public message as string
End class

i think i should go early from work today
sorry for the errors

B..M
0
 
LVL 1

Author Comment

by:icx
ID: 10859303
Hi mate,

No problems. That works beautifully. Go home and take the rest of the day off! :)

Points will be awarded to you.

Thanks agaiN!
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 10859397
I'll do it definite!
Thanks

B..M
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

13 Experts available now in Live!

Get 1:1 Help Now