|
|
||||||||||||||||||||
| Home > SOA News > Creating a VB.NET Web service | |
| SOA News: |
|
||
Post your questions to Roy Hoobler in our Enterprise Developer Forum
Focusing on reusable design Microsoft has also somewhat started promoting 'Best Practices' for software design. This includes developing more modular or 'component' based software. Taking a step back, I need to figure out what my Web service needs to do and what components are going to be needed. This article shows not only how to implement a Web service server and client, but some of the object oriented issues in designing a VB.NET application. For many, this will seem trivial, but for others, it should be a nice example of thinking in objects or better, show VB.NET capability of using objects and how they can be implemented in a Web service. What I want my Web service to do 1.Get a database connection The Web service could also provide a list of categories that would help narrow the search results. The client program will probably not know these categories, so I'll add that functionality, as well as provide a function that accepts the category and date to filter the results. Now there are two additional functions: 4.Create HTML Select List of categories Finally, I want to be able to get all the information about an event. In this case, I will create an Event object that has properties. SOAP can actually serialize these objects into XML and transform them back to objects for the client. This class can also be reusable and we will be able to test it before deploying it to our Web service: 6.Return event object for a selected event Starting the Project A Database Connection Example Following a basic design principle, I made two database classes that will make use of OLE DB. Other classes in my application will use my classes instead of OLE DB. Again, if my database changes to SQL later, I only need to change one class (possibly two) instead of every class in my application. Using DataSet objects [See Listings 1 and 2] Creating a class to do what you need done: Your interface The final version of the class has three public methods and two private methods: 1.Get Results For Date When I instantiate my class in the Web service, these methods will be accessible from any client. Here's the code from the Event Class: [See Listing 3] Now you can test your application. Add a Windows Application project to the current solution. Within this project, add a reference to your Class Library project and test each function (for example: oEventClass.getCategoryOptionList()). This is a much easier approach and easier to debug than a Web service. As you add functionality, you can test your classes offline. Plugging in your classes to create a Web service First you will need to add a third -- a new VB.NET Web service -- project to your current solution. The name of this project will be the directory on the Web server for your Web service. My new project is called companyEventsWS. You will need to connect to a Web server and have permissions to create a "virtual directory" in IIS. I usually create a separate .NET developer user account on the server and then add them to "site operators" in IIS. In the Web services project, in the project explorer window, select "Add Reference" and select your (.dll) project. When you add this reference and compile the project, VB.NET will compile the DLL and place it in a /bin directory under your Web service project -- locally and on the server. The last step. For each public method in the Event Class, I made a Web method for clients to connect to. [See Listing 4] **Note: If you use a COM component in any project, the "Interop" classes will be deployed to the Web service. However, the original COM component will need to be installed or registered. To test the Web service, open a browser and navigate to http://localhost/companEventsWS/service1.asmx. You should see the three methods and Microsoft actually let's you invoke (test) each service. If you get a http 500 error, check the location of your Access Database file and permissions. The anonymous user will need at least read access to the .mdb file. The next article will show how to use an ASP.NET application as a client for our new Web service. Summary
For More Information:
'); // -->
|
|
|||||||||||||||||||||||||
| About Us | Contact Us | For Advertisers | For Business Partners | Site Index | RSS |
|
|
|
|||||||