Web Service Tutorial
10 Pages
English

Web Service Tutorial

-

Downloading requires you to have access to the YouScribe library
Learn all about the services we offer

Description

Beginning Web Services with XCodeBeginning Web Services with XCodeJeffrey W. Pearsonjeffreywpearson@gmail.comVersion 1.02005.9.30Page 1 of 10Beginning Web Services with XCode Since the Apple Documentation ‘was lacking’ in a complete beginner’s guide to creating your first web service, and I couldn’t find a tutorial on the web, I decided to put up or shut up and write one. My many thanks to all of those on the Apple Developer’s Mailing List for the help in teaching me. If you’re not already on these lists, you need to be. This tutorial will take you by the hand in creating a web service. This is the server side. Our sample will return back the customary string of ‘hello World’. This tutorial will NOT contain the client side...mainly because I haven’t figured out how to write one yet.. :-). Once I do, and if I get some good feedback from this one, I’ll write that tutorial.Software Versions used:XCode 2.1 (IDE Version: 621, Core Version: 621, ToolSupport Version: 610)WebObjects 5.3OS X 10.4.2Providing a Web Service:1: Open XCode Application (Macintosh HD:Developer:Applications:Xcode)2: Create a new project. -File -> New Project (Shift-CMD-N)3: The new Project Dialog Opens. Select WebObjects Application for you project type. (Figure 1)Figure 1: New Project window4: Click Next.5: The WebObjects Application Assistant window appears. This is where you give your project a name. I called it HelloWorldWS. You can name it whatever you want. Keep in mind ...

Subjects

Informations

Published by
Reads 40
Language English
Beginning Web Services with XCode Beginning Web Services with XCode
Page 1 of 10
Jeffrey W. Pearson jeffreywpearson@gmail.com Version 1.0 2005.9.30
Beginning Web Services with XCode
Since the Apple Documentationwas lackingin a complete beginners guide to creating your first web service, and I couldnt find a tutorial on the web, I decided to put up or shut up and write one. My many thanks to all of those on the Apple Developers Mailing List for the help in teaching me. If youre not already on these lists, you need to be.
This tutorial will take you by the hand in creating a web service. This is the server side. Our sample will return back the customary string ofhello World. This tutorial will NOT contain the client side...mainly because I havent figured out how to write one yet.. :-). Once I do, and if I get some good feedback from this one, Ill write that tutorial.
Software Versions used: XCode 2.1 (IDE Version: 621, Core Version: 621, ToolSupport Version: 610) WebObjects 5.3 OS X 10.4.2 Providing a Web Service: 1: Open XCode Application (Macintosh HD:Developer:Applications:Xcode)
2: Create a new project.
-File -> New Project (Shift-CMD-N)
3: The new Project Dialog Opens. Select WebObjects Application for you project type. (Figure 1)
4: Click Next.
Figure 1: New Project window
5: The WebObjects Application Assistant window appears. This is where you give your project a name. I called it HelloWorldWS. You can name it whatever you want. Keep in mind this will be the name at the end of the url that is used to access your web service. Type the name in theProject Namefield. The Location entry with automatically fill in the same information as you type. (Figure 2)
Page 2 of 10
Beginning Web Services with XCode
6: Click Next.
Figure 2: WebObjects Application Assistant window
7: The J2EE Integration window appears. This is used if you wish to deploy your application outside of the We-bObjects application server environment. For the purposes of this tutorial, we will stick with WebObjects deploy-ment. Make sure theDeploy in a Servlet Containeris NOT checked. (Figure 3)
8: Click Next.
Figure 3: J2EE Integration window
9: TheWeb Service Supportwindow appears. THIS IS THE IMPORTANT ONE. Since we are talking about pro-viding a web service for this part, select theAdd Web service supportoption. (Figure 4).
Page 3 of 10
Beginning Web Services with XCode
10: Click Next.
Figure 4: Web Service Support window
11: TheChoose EOAdaptorswindow appears. For this tutorial, you dont need any of these. Deselect all options (Figure 5).
12: Click Next.
Figure 5: Choose EOAdaptors window
13: TheChoose Frameworkswindow appears. All of the default frameworks are listed. You dont need to add any for this tutorial(Figure 6).
Page 4 of 10
Beginning Web Services with XCode
14: Click Next.
Figure 6: Choose Frameworks window
15: TheChoose EOModelswindow appears. For this tutorial, you dont need any(Figure 7).
16: Click Finish.
Figure 7: Choose EOModels window
17: The window goes away. XCode does some setting up and schtuff in the background. When it is done, your project window will open(Figure 8).
Page 5 of 10
Beginning Web Services with XCode
Figure 8: Project window
18: Now we are going to write the code for our web service. Java purists need to chill through this. This is REALLY simple code and not meant to be the most incredible Java code you have ever seen. That is not the fo-cus of this tutorial. If your classes folder is not expanded, click on the arrow that is to the left of the folder and pointing to the right. The arrow rotates down and shows the current Java classes. The default ones listed should be Application, DirectAction, and Session (Figure 9).
Figure 9: Expanded Java Folder view
19: The first step is to add our own class. Click once on theClassesfolder so it is highlighted (it will turn blue). Go to the File-> New File menu. TheNew Filewindow will open(Figure 10).
Page 6 of 10
Beginning Web Services with XCode
Figure 10: New File window
20: SelectJava Classunder thePure Javacategory.
21: Click Next.
22: Thenew Java Classwindow appears. You name your class here. I have called it helloWorld(Figure 11).
23: Click theFinishbutton.
Figure 11: New Java Class window
24: XCode creates the class and opens it in a new window. The source code is displayed(Figure 12).
Page 7 of 10
Beginning Web Services with XCode
Figure 12: Source Code window for helloWorld.java file
25: On the class declaration line, between thedand the{, add “<space>extends<space>Object” (Figure 13). SAVE THE FILE (CMD-s).
Figure 13: Source Code window for helloWorld.java after step 25.
26: Create a main method in the class. The only line of code this method will have is the return of the string. The exact code is:
publicString main() { return"Hello Web Service World!!"; }
SAVE THE FILE (CMD-s). See Figure 14 for the completed class.
Page 8 of 10
Beginning Web Services with XCode
27: Close the window.
Figure 14: Completed helloWorld class
28: Open the Application.java file by double clicking on it. Figure 15 has the default source code.
Figure 15: default Application source code window
29: After/* ** Put your application initialization code here ** */,add:
WOWebServiceRegistrar.registerWebService(helloWorld.class,true); SAVE THE FILE(cmd-s). Figure 16 has the completed code.
Page 9 of 10
Beginning Web Services with XCode
30: Close the window.
Figure 16: Completed Application.java code
31: Compile and run the program. A web browser will open and you should see your “Hello World Web Service!!” in the body of the page. Thats it. You should now have a working web service.
The two keys of making the web service seem to be the
WOWebServiceRegistrar.registerWebService(helloWorld.class,true);
in the Application.java. I am assuming it is what registers your class as a web service.
The other bit is extending your class as an object.
I donthese code chunks, but they seem to be the key to making this work. If someonet know why you need would be kind enough to explain what this line is and does, I would be more than happy to update this and pass on the info.
Page 10 of 10