Solved

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

Posted on 2004-04-19
10
871 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

730 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