HighTechTalks DotNet Forums  

receive classes in parameters in web methods

Dotnet Framework (Webservices) microsoft.public.dotnet.framework.webservices


Discuss receive classes in parameters in web methods in the Dotnet Framework (Webservices) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
leon
 
Posts: n/a

Default receive classes in parameters in web methods - 12-08-2007 , 09:55 PM






Hello group,

Somebody has a example where web methods receive and send classes in the
parameters.

I looking the best way to send parameters to web service and anybody told me
something like that.

Thanks a lot for help,


leon



Reply With Quote
  #2  
Old   
Tiago Halm
 
Posts: n/a

Default Re: receive classes in parameters in web methods - 12-09-2007 , 12:38 PM






You're not supposed use "classes" as arguments to web service operations,
but use XML data that will be deserialized as a class in a language of
choice.

A web service operation is meant to specify (if any) data structures as
arguments. A data structure will be, in serialized form, XML data. Languages
like .NET allow you to use classes or structs to represent those data
structures which will be serialized/deserialized by the language itself.

In WCF, the way to go is to specify a struct/class and decorate it with
[DataContract]. As for the members of the class/struct you want exposed you
use [DataMember]. Look into MSDN for more information.

Tiago Halm

"leon" <faleusqui (AT) hotmail (DOT) com> wrote

Quote:
Hello group,

Somebody has a example where web methods receive and send classes in the
parameters.

I looking the best way to send parameters to web service and anybody told
me something like that.

Thanks a lot for help,


leon




Reply With Quote
  #3  
Old   
Spam Catcher
 
Posts: n/a

Default Re: receive classes in parameters in web methods - 12-09-2007 , 06:16 PM



"leon" <faleusqui (AT) hotmail (DOT) com> wrote in
news:uZNl07gOIHA.4688 (AT) TK2MSFTNGP06 (DOT) phx.gbl:

Quote:
I looking the best way to send parameters to web service and anybody
told me something like that.
Yes you can send a serializable class in the parameter of a web service ...
However in practice I found this to be a bad idea - Used of the web service
seem to prefer discrete parameters.

Returning a class (or DTO) is prefectly OK however.

--
spamhoneypot (AT) rogers (DOT) com (Do not e-mail)


Reply With Quote
  #4  
Old   
Spam Catcher
 
Posts: n/a

Default Re: receive classes in parameters in web methods - 12-09-2007 , 06:23 PM



"Tiago Halm" <thalm (AT) nospam (DOT) hotmail.com> wrote in
news:#uT0FpoOIHA.4136 (AT) TK2MSFTNGP03 (DOT) phx.gbl:

Quote:
You're not supposed use "classes" as arguments to web service
operations, but use XML data that will be deserialized as a class in a
language of choice.
That's schematics - but also should clarify that:

Parameters can be Primatives, Objects (serialized object), XMLNode, or a
raw XML (String).

Quote:
A web service operation is meant to specify (if any) data structures
as arguments. A data structure will be, in serialized form, XML data.
Languages like .NET allow you to use classes or structs to represent
those data structures which will be serialized/deserialized by the
language itself.


--
spamhoneypot (AT) rogers (DOT) com (Do not e-mail)


Reply With Quote
  #5  
Old   
tiago.halm@gmail.com
 
Posts: n/a

Default Re: receive classes in parameters in web methods - 12-10-2007 , 06:06 AM



On Dec 9, 11:23 pm, Spam Catcher <spamhoney... (AT) rogers (DOT) com> wrote:
Quote:
Parameters can be Primatives, Objects (serialized object), XMLNode, or a
raw XML (String).

Indeed, however the OP was asking about classes.

In the general case using complex types if the preferred method
because it gives you more flexibility regarding upgrades and non-
breaking changes to the operation "signature". Primitive types are
obviously possible, but tend to seal the operation for future changes.
Serialized objects are possible but tend to hurt interoperability.
XMLNodes and raw xml are possible but again tend to be difficult to
manipulate.

Tiago Halm


Reply With Quote
  #6  
Old   
leon
 
Posts: n/a

Default Re: receive classes in parameters in web methods - 12-10-2007 , 09:28 AM



ok, well, i need to make a web service where it allow upload, download, get
and delete files.
So, i need you advice about what is the best way to build it, but always
thinking in architecture.

thnaks a lot group.

leon



"Spam Catcher" <spamhoneypot (AT) rogers (DOT) com> wrote

Quote:
"leon" <faleusqui (AT) hotmail (DOT) com> wrote in
news:uZNl07gOIHA.4688 (AT) TK2MSFTNGP06 (DOT) phx.gbl:

I looking the best way to send parameters to web service and anybody
told me something like that.

Yes you can send a serializable class in the parameter of a web service
...
However in practice I found this to be a bad idea - Used of the web
service
seem to prefer discrete parameters.

Returning a class (or DTO) is prefectly OK however.

--
spamhoneypot (AT) rogers (DOT) com (Do not e-mail)



Reply With Quote
  #7  
Old   
tiago.halm@gmail.com
 
Posts: n/a

Default Re: receive classes in parameters in web methods - 12-10-2007 , 10:03 AM



For the upload operation a simple example below:

Files are always an array of bytes, so -- byte[].
Your uploads will probably refer the name you want to give the file,
so -- string name.

[DataContract(Name="UploadInput")]
class UploadInput
{
[DataMember(Name="Data", Order="0")]
byte[] data;
[DataMember(Name="Name", Order="1")]
string name;
}

[ServiceContract(Name="FileManager")]
interface IFileManager
{
[OperationContract(Name="Upload")]
void Upload(WsFileInfo uploadInput)
}

class ServiceImpl : IFileManager
{
/* interface implementation */
(...)
}

--

Going forward, you need to define the kind of input and output you
need for each operation. Also, use namespaces that allow you to
version the datacontracts, the portTypes (interfaces), the service
implementation.

As for performance, if there is no instance state involved, opt for
InstanceContextMode=InstanceContextMode.Single for best throughput.
Opt also for ConcurrencyMode=ConcurrencyMode.Multiple if thread-safe
behavior is garanteed.

As for exposure, consider netNamedPipeBinding or netTcpBinding to
achieve best throughput. basicHttpBinding and wsHttpBinding are also
options required when hosting in IIS6. IIS7 will allow you to to
explore the other bindings I mentioned while taking advantage of
recycling and high availablity as offered by WAS.

Ultimately, understand the scenario where this service will be
applicable and how its used. It should give you the best understanding
of how it should evolve in short term so that the design is flexible
enough to handle changes.

Hope it helps
Tiago Halm

Reply With Quote
  #8  
Old   
leon
 
Posts: n/a

Default Re: receive classes in parameters in web methods - 12-13-2007 , 09:10 AM



Thank you Thiago,

i´m trying do it.

leon


<tiago.halm (AT) gmail (DOT) com> wrote

Quote:
For the upload operation a simple example below:

Files are always an array of bytes, so -- byte[].
Your uploads will probably refer the name you want to give the file,
so -- string name.

[DataContract(Name="UploadInput")]
class UploadInput
{
[DataMember(Name="Data", Order="0")]
byte[] data;
[DataMember(Name="Name", Order="1")]
string name;
}

[ServiceContract(Name="FileManager")]
interface IFileManager
{
[OperationContract(Name="Upload")]
void Upload(WsFileInfo uploadInput)
}

class ServiceImpl : IFileManager
{
/* interface implementation */
(...)
}

--

Going forward, you need to define the kind of input and output you
need for each operation. Also, use namespaces that allow you to
version the datacontracts, the portTypes (interfaces), the service
implementation.

As for performance, if there is no instance state involved, opt for
InstanceContextMode=InstanceContextMode.Single for best throughput.
Opt also for ConcurrencyMode=ConcurrencyMode.Multiple if thread-safe
behavior is garanteed.

As for exposure, consider netNamedPipeBinding or netTcpBinding to
achieve best throughput. basicHttpBinding and wsHttpBinding are also
options required when hosting in IIS6. IIS7 will allow you to to
explore the other bindings I mentioned while taking advantage of
recycling and high availablity as offered by WAS.

Ultimately, understand the scenario where this service will be
applicable and how its used. It should give you the best understanding
of how it should evolve in short term so that the design is flexible
enough to handle changes.

Hope it helps
Tiago Halm



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.