Solved

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

Posted on 2004-04-19
10
856 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Disable and re-enable a dynamic System.Timers.Timer 6 42
ASP.NET reading ATOM 2 53
Turn on intranet settings 1 42
Run time Error 4 35
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

861 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

23 Experts available now in Live!

Get 1:1 Help Now