Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > How to pass a user defined type to a Webservice?

Reply
Thread Tools

How to pass a user defined type to a Webservice?

 
 
Henke
Guest
Posts: n/a
 
      08-14-2003
I know the webservice can have methods that take (some) .NET types as
arguments, but is it possible to write a method that takes a user defnined
class as a parameter? If yes, can someone please show me an example?

Thanks in advance?

/Henke


 
Reply With Quote
 
 
 
 
Henke
Guest
Posts: n/a
 
      08-18-2003
Can the classes have any methods or am I stuck to creating clases with
public properties, only?
/Henke

"Wor Tony" <(E-Mail Removed)> skrev i meddelandet
news:%(E-Mail Removed)...
> "Henke" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > I know the webservice can have methods that take (some) .NET types as
> > arguments, but is it possible to write a method that takes a user

defnined
> > class as a parameter? If yes, can someone please show me an example?
> >
> > Thanks in advance?
> >
> > /Henke
> >

> Create your class in your chosen .Net language (or create an .xsd schema
> and generate the classes using xsd.exe).
>
> Write your webmethod:
> [WebMethod]
> public MyReturnClass AcceptMyClass(MyInputClass myInputClass)
> {
> // do something with the input class and return an instance of
> // MyReturnClass
> }
>
> that's about it!
>
> HTH
>
> Wor Tony
> Nottingham - UK
>
>



 
Reply With Quote
 
 
 
 
Sam Vanhoutte
Guest
Posts: n/a
 
      08-18-2003

"Henke" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Can the classes have any methods or am I stuck to creating clases with
> public properties, only?
> /Henke
>

The classes can have methods, but these methods are not serialized, as they
never contain state...
Clients need to have objects with the same properties, but they don't need
to have these methods...


 
Reply With Quote
 
Simon Smith
Guest
Posts: n/a
 
      09-01-2003
"Wor Tony" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> "Sam Vanhoutte" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >
> > "Henke" <(E-Mail Removed)> wrote in message
> > news:%(E-Mail Removed)...
> > > Can the classes have any methods or am I stuck to creating clases with
> > > public properties, only?
> > > /Henke
> > >

> > The classes can have methods, but these methods are not serialized, as

> they
> > never contain state...
> > Clients need to have objects with the same properties, but they don't need
> > to have these methods...
> >

> Yep. As Sam has already said, no methods, just public properties.
>
> If you create an xsd, then the client and your web service can validate the
> objects using
> schema validation.
>
> HTH
>
> AP
> Nottingham - UK


The way to do this is:

First create the classes you want to send in a separate assembly. In
the Web Service project reference that assembly and construct and
return the class you want.
In the Client project reference the assembly containing the class(es)
you want to sent. Then create (or update) the Web Reference.
Now open up the Reference.cs associated with the Web reference. At the
bottom you will find a class definition containing the fields og the
class as public fields. DELETE THIS BIT OF CODE!
At the top of the Reference.cs add a 'using' for the assembly which
contains the passed class, and add the same using wherever you call
the Web Service. Compile. Go.

If later you update the Web reference the deleted class definition
will be reinstated and the client will not compile. Fine. Go back and
delete the generated class definition and add the using to the
Reference.cs and all will be OK.

HTH
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
mapping betwing a standard type and a user defined type with SWIG Lyes Amazouz Ruby 2 08-20-2008 04:01 PM
Type conversion function for user defined type... zaeminkr@gmail.com C++ 1 05-16-2007 09:00 AM
casting primitive type to user-defined type works in usage xllx.relient.xllx@gmail.com C++ 2 04-15-2006 05:37 AM
#if (defined(__STDC__) && !defined(NO_PROTOTYPE)) || defined(__cplusplus) Oodini C Programming 1 09-27-2005 07:58 PM



Advertisments