Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Omg i think this is a noobie question...

Here is the deal.

I got a simple function in my webservice that atm. only returns a userid.

The code looks like this:
<WebMethod(Description:=".")> Public Function Logon(ByVal Nick As String)
As Integer

Logon = 1
End Function

But what i want to return is more params, like id, lastlogin, realname etc.

So i want the xml to look like this:
<Logon>
<Id>1</Id>
<LastLogin>2002-10-10 22:00:05</LastLogin>
<RealName>Kalle Anka</RealName>
</Logon>

How do i name the ID, LastLogin, RealName nodes?
[630 byte] By [peak] at [2007-11-9 19:47:21]
# 1 Re: Omg i think this is a noobie question...
One way of doing what you are after is to return an object:
i.e.

Class LoginReturnInfo
public property ID as string
...

public property LastLogin as system.datetime
...
End Class

><WebMethod(Description:=".")> Public Function Logon(ByVal Nick As String)
As LoginReturnInfo

For this to work, your object must be serializable. Theres a bunch of ways
of making sure this is so, but to keep it simple, just make sure your return
info class has a parameter-less default constructor, and all the properties
are read/write.

"peak" <peak@carmack.nu> wrote:
>
>Here is the deal.
>
>I got a simple function in my webservice that atm. only returns a userid.
>
>The code looks like this:
><WebMethod(Description:=".")> Public Function Logon(ByVal Nick As String)
>As Integer
>
>Logon = 1
>End Function
>
>But what i want to return is more params, like id, lastlogin, realname etc.
>
>So i want the xml to look like this:
><Logon>
> <Id>1</Id>
> <LastLogin>2002-10-10 22:00:05</LastLogin>
> <RealName>Kalle Anka</RealName>
></Logon>
>
>How do i name the ID, LastLogin, RealName nodes?
Anthony Glenwright at 2007-11-11 22:04:45 >
# 2 Re: Omg i think this is a noobie question...
Returning objects isn't a good idea ... it's not very compatible with other
platforms that might use the WebService. I recommend creating a DataSet, and
populating it with your data and then simply return ds.GetXML(), which will
return an XML string.

~~Bonnie

"Anthony Glenwright" <anthony.glenwright@inventua.com> wrote in message
news:3d7ec6c2$1@10.1.10.29...
>
> One way of doing what you are after is to return an object:
> i.e.
>
> Class LoginReturnInfo
> public property ID as string
> ...
>
> public property LastLogin as system.datetime
> ...
> End Class
>
>
> ><WebMethod(Description:=".")> Public Function Logon(ByVal Nick As String)
> As LoginReturnInfo
>
> For this to work, your object must be serializable. Theres a bunch of
ways
> of making sure this is so, but to keep it simple, just make sure your
return
> info class has a parameter-less default constructor, and all the
properties
> are read/write.
>
> "peak" <peak@carmack.nu> wrote:
> >
> >Here is the deal.
> >
> >I got a simple function in my webservice that atm. only returns a userid.
> >
> >The code looks like this:
> ><WebMethod(Description:=".")> Public Function Logon(ByVal Nick As String)
> >As Integer
> >
> >Logon = 1
> >End Function
> >
> >But what i want to return is more params, like id, lastlogin, realname
etc.
> >
> >So i want the xml to look like this:
> ><Logon>
> > <Id>1</Id>
> > <LastLogin>2002-10-10 22:00:05</LastLogin>
> > <RealName>Kalle Anka</RealName>
> ></Logon>
> >
> >How do i name the ID, LastLogin, RealName nodes?
>
Bonnie Berent at 2007-11-11 22:05:41 >
# 3 Re: Omg i think this is a noobie question...
Bonnie,

If you return an object from a web service, it is serialized to XML. I don't
see how applications written for non .NET platforms would have any trouble
consuming your web service - .NET handles this all very well.

"Bonnie Berent" <bonnieb@profitware-online.com> wrote:
>Returning objects isn't a good idea ... it's not very compatible with other
>platforms that might use the WebService. I recommend creating a DataSet,
and
>populating it with your data and then simply return ds.GetXML(), which will
>return an XML string.
>
>
>~~Bonnie
>
>
>"Anthony Glenwright" <anthony.glenwright@inventua.com> wrote in message
>news:3d7ec6c2$1@10.1.10.29...
>>
>> One way of doing what you are after is to return an object:
>> i.e.
>>
>> Class LoginReturnInfo
>> public property ID as string
>> ...
>>
>> public property LastLogin as system.datetime
>> ...
>> End Class
>>
>>
>> ><WebMethod(Description:=".")> Public Function Logon(ByVal Nick As String)
>> As LoginReturnInfo
>>
>> For this to work, your object must be serializable. Theres a bunch of
>ways
>> of making sure this is so, but to keep it simple, just make sure your
>return
>> info class has a parameter-less default constructor, and all the
>properties
>> are read/write.
>>
>> "peak" <peak@carmack.nu> wrote:
>> >
>> >Here is the deal.
>> >
>> >I got a simple function in my webservice that atm. only returns a userid.
>> >
>> >The code looks like this:
>> ><WebMethod(Description:=".")> Public Function Logon(ByVal Nick As String)
>> >As Integer
>> >
>> >Logon = 1
>> >End Function
>> >
>> >But what i want to return is more params, like id, lastlogin, realname
>etc.
>> >
>> >So i want the xml to look like this:
>> ><Logon>
>> > <Id>1</Id>
>> > <LastLogin>2002-10-10 22:00:05</LastLogin>
>> > <RealName>Kalle Anka</RealName>
>> ></Logon>
>> >
>> >How do i name the ID, LastLogin, RealName nodes?
>>
>
>
Anthony Glenwright at 2007-11-11 22:06:44 >
# 4 Re: Omg i think this is a noobie question...
Yes, .NET handles it just fine ... other platforms is another story. Try it
from Java or Visual FoxPro for example. Not so easily consumed.

~~Bonnie

"Anthony Glenwright" <anthony.glenwright@inventua.com> wrote in message
news:3d9e9434$1@10.1.10.29...
>
> Bonnie,
>
> If you return an object from a web service, it is serialized to XML. I
don't
> see how applications written for non .NET platforms would have any trouble
> consuming your web service - .NET handles this all very well.
>
> "Bonnie Berent" <bonnieb@profitware-online.com> wrote:
> >Returning objects isn't a good idea ... it's not very compatible with
other
> >platforms that might use the WebService. I recommend creating a DataSet,
> and
> >populating it with your data and then simply return ds.GetXML(), which
will
> >return an XML string.
> >
> >
> >~~Bonnie
> >
> >
> >"Anthony Glenwright" <anthony.glenwright@inventua.com> wrote in message
> >news:3d7ec6c2$1@10.1.10.29...
> >>
> >> One way of doing what you are after is to return an object:
> >> i.e.
> >>
> >> Class LoginReturnInfo
> >> public property ID as string
> >> ...
> >>
> >> public property LastLogin as system.datetime
> >> ...
> >> End Class
> >>
> >>
> >> ><WebMethod(Description:=".")> Public Function Logon(ByVal Nick As
String)
> >> As LoginReturnInfo
> >>
> >> For this to work, your object must be serializable. Theres a bunch of
> >ways
> >> of making sure this is so, but to keep it simple, just make sure your
> >return
> >> info class has a parameter-less default constructor, and all the
> >properties
> >> are read/write.
> >>
> >> "peak" <peak@carmack.nu> wrote:
> >> >
> >> >Here is the deal.
> >> >
> >> >I got a simple function in my webservice that atm. only returns a
userid.
> >> >
> >> >The code looks like this:
> >> ><WebMethod(Description:=".")> Public Function Logon(ByVal Nick As
String)
> >> >As Integer
> >> >
> >> >Logon = 1
> >> >End Function
> >> >
> >> >But what i want to return is more params, like id, lastlogin, realname
> >etc.
> >> >
> >> >So i want the xml to look like this:
> >> ><Logon>
> >> > <Id>1</Id>
> >> > <LastLogin>2002-10-10 22:00:05</LastLogin>
> >> > <RealName>Kalle Anka</RealName>
> >> ></Logon>
> >> >
> >> >How do i name the ID, LastLogin, RealName nodes?
> >>
> >
> >
>
Bonnie Berent at 2007-11-11 22:07:39 >
# 5 Re: Omg i think this is a noobie question...
Test

--
Please do not send email directly to this alias. This alias is for newsgroup
purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
"peak" <peak@carmack.nu> wrote in message news:3d737410$1@10.1.10.29...
>
> Here is the deal.
>
> I got a simple function in my webservice that atm. only returns a userid.
>
> The code looks like this:
> <WebMethod(Description:=".")> Public Function Logon(ByVal Nick As String)
> As Integer
>
> Logon = 1
> End Function
>
> But what i want to return is more params, like id, lastlogin, realname
etc.
>
> So i want the xml to look like this:
> <Logon>
> <Id>1</Id>
> <LastLogin>2002-10-10 22:00:05</LastLogin>
> <RealName>Kalle Anka</RealName>
> </Logon>
>
> How do i name the ID, LastLogin, RealName nodes?
Steve Swartz at 2007-11-11 22:08:41 >