Solved

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

Posted on 2004-04-19
10
865 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

791 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