Title: Reduction - Develop Web Services using WebLogic Workshop8.1
[comment]
Author: Liu Guodong (dev2dev ID: yahoo163)
introduction
Web services have been recognized by a standard for next-generation network services. Many major manufacturers have implemented support for Web services on their own technical platform. As a web-based distributed application, the web service can be used by a variety of client programs. If you implement an app developed as a web service, then, no matter where you will use your app, you are Java, VB, C or C # does not have to write a dedicated interface to call this service. In order to implement the web service, it can be called by any client, which uses the following technique:
Service Release / Discovery: UDDI Service Description: WSDL XML Message: SOAP Transfer Protocol: HTTP, SMTP, FTP, HTTPS, TCP / IP
We are not difficult to see from the series of concepts and technologies listed above, and things to achieve and publish a web service need are quite a lot. I used to write a service to use Apache SOAP. After application implementation, the service description to the final deployment finally completed a service of HelloWold messages, but very complex cumbersome. However, now if you use WebLogic Workshop8.1 development web services, you will find that developing a web service will be very simple, even give you the feeling like a wood is so easy. Ok, talk less, let us use excellent WebLogic Workshop8.1 to develop our first web service with WebLogic Server 8.1.
Example in the article
Before I started this article, I will introduce it first, what we will want to achieve is what is going. Our first service is very simple, just write a service on the console on the console in the WebLogic Workshop8.1 environment, followed by further explanation How to write a customer running outside WebLogic Workshop Negotiate this service.
Ready to work
In order to run the example we will talk, we need to download the latest version of WebLogic Platform8.1 from the BEA site. The DEV2DEV Chinese site of the BEA offers a download link, you can download it from here http://dev2dev.bea.com.cn/. The following installation step is very simple, because it is a Chinese version that you will complete with its prompt (general choice for default settings).
In addition, in order to be able to better run and debug the example, it is recommended that your computer configuration is best in CPU: P4, memory 512M, and my development platform is Windows2000. Of course this is not necessary.
Write a HelloWorld service
Almost most of the entry introduction articles like to start with HelloWorld, I also use it to start to introduce how to quickly develop web services using WebLogic Workshop8.1.
After the WebLogic Platform8.1 is installed, you can see the link of WebLogic Workshop in the program menu, click Open it. We will see the interface below. The interface is a complete Chinese version and its help is also Chinese, and it is very good.
Now create a new project, choose to build an "empty application", name MYWEB, save below the E: MyWeb folder:
Under this app, we can create a web service. Click "New-> Project" on the application directory to create a new WewebServices, as shown:
Click "New-> WebServices" on this newly built WebServices project to create a web service name HelloWorld, which is a file that is .jws is a subscripted file. We will add our own methods and features on this service. After you finish, you will see the following screen, which represents a web service name called "HelloWorld", although there is a service but it doesn't make anything, let us add a method to the WebLogic console. Print the "HelloWorld" string. Right click on the panel of the HelloWorld service, select the addition method:
The method we add is named "Sayello". After adding, click "Source Code Window". We can see the following line of code:
Public class helloworld implements com.bea.jws.webservice
{
Static Final long serialversionuid = 1L;
/ **
* @common: Operation
* /
Public void sayhello ()
{
System.out.Println ("HelloWorld");
}
}
Code Description: WebLogicWorkshop's .jws file, and a general Java file format use the standard Java class write, all Java language specification also applies to pre-.jws, here WebLogic Workshop extends the Java's Javadoc extension. Note Note The @common: Operation in the Note It will tell WebLogic Workshop This is a way to operate, this SayHello method is exposed as a service to the client. If this tag is removed, this method is used as an internal method of Java that does not expose to the client.
System.out.Println ("HelloWorld"); a line is the function we print to the console.
Of course, as part of the web service, we can also generate a description file for this service. Complete this step as long as you click "Generate WSDL File" on the HelloWorld.jws file, the tool will automatically generate the WSDL file that describes this service:
Run and test service
Now one of the simplest WebServices is complete, it is very simple to test whether this service is running normally. WebLogic Workshop provides a powerful debugging. We want to test this service just click the button in the toolbar. If your WebLogic Server does not start, it will prompt whether to start the server, "Yes: Start the application server (this may be slower, depending on your computer configuration), you will see the picture below.
WebLogic Workshop also compiles and packages this service while starting the application server, automatically generates a client that tests this service, and automatically opens the browser to display a test page:
Click on the "Sayello" button now. See what happened to the WebLogic Server console? That's right on our console display "HelloWorld" string.
Ok, a simplest web service is completed. Is it very easy, although it is easy, but this does not mean that the function will be lacking, we now generated Web services can be accessed by any WebLogicWorkshop unexpected program. Let's talk about how to issue a service and how to write a Java client to access this service.
Service release
Big bag in WebLogic Workshop and publish a service is very simple. Click "Generate -> Generate EAR File" in the menu. Pack this service is a .ser file.
The packaged file can be found in the E: MyWeb directory, the default use MyWeweb.ear. You can release your web service now. WEBLOGICPALTFORM8.1 releases web services is very simple, you only need to copy the MyWeb.ear to your WebLogic Server application directory, I am in d: Eauser_projectsapplicationsMydomaIndefaultWebApp directory. Below I will tell how to write a client to access this service.
Write the client
If you have written someone who wrote a Web service called, you must remember which terrible energy, because you have to care about the location of the specific service, WSDL description information, etc. It is very simple in WebLogicworkshop. Remember the test page that we opened in WebLogicWorkshop in testing HelloWorkshop? Click on the "Overview" link on this page, there is a "Java Agent" and "Proxy Support Jar" on the page. Download them down:
These two classes provide us with an agent class for accessing services. Now you have to copy them to D: Eauser_ProjectsApplicationSmyDomainDefaultwebappweb-inflib, so that I can write the classes in the two packs for a while. Just like the description seen above, "You can use the classes contained in these Web services, as if it is the same as the local Java class." Let us now write a JSP client to access this service. I give this JSP source code as follows:
<% @ page contenttype = "text / html; charset = GBK"%>
<% @ page import = "WebLogic.jws.Proxies. *"%> // Import Agent Class
<%
HelloWorld_Impl Helloimp; // Service class agent implementation
HelloWorldsoap Hellosoap;
Try {
HelloIMP = New HelloWorld_Impl ();
Hellosoap = helloimp.gethelloworldsoap (); // Get the object of this service
Hellosoap.SAYHELLO (); // Call method, print "helloworld"
}
Catch (Exception EX) {
EX.PrintStackTrace ();
}
%>
This client does not make anything, just simply call the SayHello method in the HelloWorld service, allowing it to promise "HelloWorld" strings on the server console. You can see that although this service is on a remote server but I am calling it and calls a normal Java class.
in conclusion
I showed you how to develop, deploy, and debug a service in WebLogicWorkshop8.1, and finally use JSP as the client to call this service. You can see this process is very simple, you don't need to write a cumbersome WSDL file, or you don't have to write a proxy class that the client calls, most of the things WebLogicWorkshop is completed for you. This really saves a lot of time for our development efforts. We can put more energy on the actual business process description. Ok, I hope this article can be used as a start, bringing you into the World of Web services, enabling you to use the convenience of WebLogicWorkshop's convenience to the next generation of Web service technology.
Author: Liu Guodong
self introduction:
2000 graduates have been engaged in software development after graduation. It has been involved in the development of multiple projects, using technology including EJB, SELVLET, JSP, STRUTS, JDO, Web Services, etc.