As a small bamboo of 9CBS JavawebService, I will still want to write some basic articles about JWS. I have been public and busy. I have been unintentional, so I will drag again. I have seen my plaque. I have asked questions about Java calling WebService. He is determined to write this article to share it. Equipment: JDK1.4.1_02, about this problem, there is no need to say it. ^ _ ^ Java Web Services Developer Pack 1.2 (http://java.sun.com/webservices/downloads/webservicespack.html) My JWSDP installation path is e: /minitool/jwsdp-1.2/, in the article, Not sound. Platform: Microsoft Windows 2000 [Version 5.00.2195]
Full text takes Google's WebService as an example, it provides a development kit, http://www.google.com/apis/download.html, but a lot of WebService will not be like this, just tell you a WSDL (WebService Description Language) file. But this has no essential difference, which also contains such a file Googlesearch.wsdl in Google's development kit. Most WebService clients have developed, I know that the WSDL file is already, but Google needs a licenseKey, because it is just testing, so this limit is only one000 to query 1000 or 2000 times, I forgot, I applied for two, in my C # demonstration site (http://63.210.240.215/rookieport/) used two licenseKey, regarding this C # presentation site and source files see http: //www10.brinkster.com/rookieport/default.aspx. Unfortunately, I can't update this two sites, there is no free lunch in the world! ! ! Ok, the theme of this article is JavawebService instead of C # WebService, after preparing, we have a slight analysis of the WSDL file, this file is mainly description WebService specifically used which data structure (described in Types), which provides Web service function (described in Operation), and the access address of the service (described in Service), about WSDL is not detailed, find time to make up.
In GoogleSearch.wsdl, we see a Dogooglesearch Operation, from the name we can see that this method should be a search service, a parameters describing the Dogooglesearch call:
Later we go down to see a description of the return type of the doGoogleSearch:
This describes the data structure of GooglesearchResult, with the properties of Type = "XSD: XXX", which also uses two composite type ResulTelementArray, and DirectoryCateGoryArray readers can continue to analyze, these data types will be by JWS The interpreted conversion tool generates the corresponding Java class. The two types of Array ended, which also generated a corresponding ArrayOfxxxxx class before jwsdp1.1, now 1.2 is better, and directly mapped to the Java array. Well, we can enter the first step in the actual operation of the client development. First we need to edit a config file in an XML format, the form is as follows: XML Version = "1.0" Encoding = "UTF-8"?> < Configuration XMLns = "http://java.sun.com/xml/ns/jax-rpc/ri/config">
Directory of C: / Googleapi
[.] [..] README.txt GoogleAPIDemo.javaGoogleSearch.wsdl APIs_Reference.htmlLICENSE.txt googleapi.jar [javadoc] [dotnet] [soap-samples] [licenses] google.configJavaWebService client Concise Guide to establish a client's .txt Directory C: /> MKDIR Client Executes WSCompile Generate Client Files C: / Googleapi> E: /MINITOOL/JWSDP 1.2/Jaxrpc/bin/wscompile -gen -gen -dclient -keep google.config -genfig -gen parameter tells the compiler to generate WebService The client file, the -d client saves the generated file, and -keep indicates the retained intermediate file. After execution, enter the client / rook / search to see the generated series Java and Java class files.
In the third step, we create a client call file. Find the top ten records containing the cookie's Chinese page, then print the title and URL. Import rook.searcher. *; import java.rmi. *;
public class Searcher {public static void main (String [] args) {try {GoogleSearchPort sport = new GoogleSearchService_Impl () getGoogleSearchPort ();. GoogleSearchResult result = sport.doGoogleSearch ( "OyGtVqM5YRRS7hFXHLWEodMSEbiZlmc9", "rookie", 0, 10, true, "Lang_ZH-CN", True, "Lang_ZH-CN", "UTF-8", "UTF-8"); // The first parameter is licenseKey ResulTelement [] results = result.getresultElements (); for (int idx) = 0; idx
Step 5, execute. C: / Googleapi / Client> Java -cp E: /minitool/jwsdp-1.2/jaxrpc/lib/jaxrpc-impl.jar; E: /MINITOOL/JWSDP 1.2/jaxrpc/lib/jaxrpc-api.jar; E: /minitool/jwsdp-1.2/jwsdp-shared/lib/jax-qname.jar ;/minitool/jwsdp-1.2/jwsdp-shared/lib/activation.jar ;:/minitool/jwsdp-1.2/jwsdp-shared /LIB/mail.jar ;/minitool/jwsdp 1.2/jwsdp-shared/lib/xsdlib.jar ;/minitool/jwsdp-1.2/saaj/lib/saaj-api.jar ;/minitool/ JWSDP-1.2 / Saaj / Lib / Saaj-Impl.jar; E: /MINITOOL/JWSDP 1.2/jwsdp-shared/lib/commons-logging.jar; E: /MINITOOL/JWSDP 1.2/jaxp/lib/endorsed/ XerceSIMPL.jar; E: /MINITOL/JWSDP 1.2/jaxp/lib/endorsed/Dom.jar ;. Searcher
The full text ended this, taking the basic steps developed by JavaWebService client, I hope to be able to throw the jade! Unknown in the text, please advise: zlyperson@163.net