jdross
jdross

Reputation: 1206

referencing a class as a web service

Whats the best way to implement this.

I am building application that will be hosted as a web service. This app takes an employeeID and returns an employee object that contains lots of info regarding the employee. (name, status, full-time/part-time, etc)

I want the two existing apps we have (and more to come) to be able to call a method that the web service will have and return the employee object. (also at time this web service that returns the object may have new fields added to it - Pay rate, etc)

How would I go about creating a new object from this web service reference in the existing applications.

Would I decalre it like Dim Employee as new emp_webservice.employee ?

And then be able to use this object within the app? Or would the better practice be to also included the same class files? It seems like this would not be the way to go, since if I make a change to that class I then have to make it in all places

Thanks for any clarification on this.

Upvotes: 1

Views: 1009

Answers (1)

competent_tech
competent_tech

Reputation: 44941

When you add a reference to a web service in a .net application, the objects exposed by that web service exist in the namespace that you created for that web service when it was added to your application.

So, any reference to classes from that web service would need to reference the namespace for that web service, as you have indicated. You could also have an Imports WebServiceNameSpace if you don't want to fully qualify every class.

You can't really include the class files if you are using the automatic web service interface generation functionality that VS.Net provides.

Also, if you change properties in the web service, those updated properties won't be propagated to the client until you update the web service reference in your project.

Finally, if you want to add methods or additional properties to the web service classes on the client side, you can use Partial classes.

For example, let's say that the web service only provides an hourly pay rate, but I want to show a weekly salary in the client. I can extend the web service class as follows:

Namespace emp_webservice
  Partial Public Class employee
      Public Function GetWeeklyPayRate() As Decimal
          Return Me.HourlyRate * 8 * 5
      End Function
  End Class
End Namespace

Upvotes: 2

Related Questions