Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-04-19
10
Medium Priority
?
899 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 480 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

783 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