Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WebService - Expose a Class and its properties

Status
Not open for further replies.

davida37

IS-IT--Management
May 10, 2006
113
GB
Hi,

VS.NET 2005 - Visual Basic

I have just written my first Webservice and have exposed a couple of funtions/subs using:

<WebMethod()> Public Sub Finish(ByVal JobID As Integer, ByVal JobStatus As JobStatus)

I would like to expose a class also and its public properties. Is it possible to do this with Webservices? and how do I do this? Ideally, I dont want to have to create this as a function/sub and have all the variable properties as parameters.

If I put the <WebMethod()> Attribute before the class I want to make public i.e. <WebMethod()> Public Class EIMail

I get the following error....

Error 1 Attribute 'WebMethodAttribute' cannot be applied to 'EIMail' because the attribute is not valid on this declaration type. c:\inetpub\ 11 2
Please help.
thanks
 
You generally would not expose properties as a web service.

Think about it -- I make a call to your service ... IIS creates a new instance for me ... IIS sets the property to the value that I gave it ... and then IIS disposes of the object because the call is complete. Where did my value go? Into thin air.

So what you generally do is create methods only in your web service class that perform an action the caller wants. Most of the non-trivial examples would involve making changes to a database (adding a new Customer, updating an InvoiceLine, etc). Because the changes get written to the database, they survive subsequent calls to the web service.

In the specific error you're getting, the WebMethod attribute can only be applied to methods, not classes. Mark your class with the WebService attribute.

Chip H.


____________________________________________________________________
www.chipholland.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top