This type of client application, therefore, runs inside a WebLogic Server container. The sections that follow describe how to use Oracle's implementation of the JAX-RPC specification to invoke a web service from a Java client application. You can use this implementation to invoke web services running on any application server, both WebLogic and non-WebLogic.
In addition, you can create a client that runs as part of a WebLogic Server, or a standalone client that runs in an environment where WebLogic Server libraries are not available. In addition to the command-line tools described in this section, you can use an IDE, such as Oracle JDeveloper, for proxy generation and testing. The following table summarizes the main steps to create a Java SE client that invokes a web service.
Open a command window and execute the setDomainEnv. Update your build. Get information about the web service, such as the signature of its operations and the name of the ports. Write the client application Java code that includes code for invoking the web service operation.
These artifacts include:. Before you can execute the clientgen WebLogic web service Ant task, you must specify its full Java classname using the standard taskdef Ant task.
You must include the wsdl and destDir attributes of the clientgen Ant task to specify the WSDL file from which you want to create client-side artifacts and the directory into which these artifacts should be generated. The packageName attribute is optional; if you do not specify it, the clientgen task uses a package name based on the targetNamespace of the WSDL. In this example, the package name is set to the same package name as the client application, examples.
If you set the package name to one that is different from the client application, you would need to import the appropriate class files.
For example, if you defined the package name as examples. The JavaBean classes are generated into the destDir directory. For a full sample build. To execute the clientgen Ant task, along with the other supporting Ant tasks, specify the build-client target at the command line:. See the clientclasses directory to view the files and artifacts generated by the clientgen Ant task. You need to know the name of the web service and the signature of its operations before you write your Java client application code to invoke an operation.
There are a variety of ways to find this information. These files are generated into the directory specified by the destDir attribute, with subdirectories corresponding to either the value of the packageName attribute, or, if this attribute is not specified, to a package based on the targetNamespace of the WSDL.
The ServiceName. If the web service was implemented with a JWS file, the name of the web service is the value of the serviceName attribute of the WebService JWS annotation and the name of the port is the value of the portName attribute of the WLHttpTransport annotation. The PortType. In the following code example, a Java application invokes a web service operation. The client application takes a single argument: the WSDL of the web service.
The application then uses standard JAX-RPC API code and the web service-specific implementation of the Service interface, generated by clientgen, to invoke an operation of the web service.
The example also shows how to invoke an operation that has a user-defined data type examples. BasicStruct as an input parameter and return value. The clientgen Ant task automatically generates the Java code for this user-defined data type.
The following code shows how to invoke the echoComplexType operation of the ComplexService web service:. The echoComplexType operation returns the user-defined data type called BasicStruct.
The method of your application that invokes the web service operation must throw or catch java. RemoteException and javax. Add javac tasks to the build-client target in the build. In the preceding example, the clientgen -generated Java source files and the resulting compiled classes end up in the same directory clientclasses.
Although this might be adequate for prototyping, it is often a best practice to keep source code even generated code in a different directory from the compiled classes. To do this, set the destdir for both javac tasks to a directory different from the srcdir directory.
You must also copy the following clientgen -generated files from clientgen 's destination directory to javac 's destination directory, keeping the same subdirectory hierarchy in the destination:.
To run the client application, add a run target to the build. The run target invokes the Main application, passing it the URL of the deployed web service as its single argument.
Rerun the build-client target to regenerate the artifacts and recompile into classes, then execute the run target to invoke the echoStruct operation:. You can use the build-client and run targets in the build. The following example shows a complete build. It is also assumed that you use Ant in your development environment to build your client application, compile Java files, and so on, and that you have an existing build. The following list describes the changes you must make to the build.
See Sample build. Set the required wsdl attribute to the WSDL of the web service to be invoked. These include the JAX-RPC stubs of the invoked web service, as well as the Java representation of any user-defined data types used as parameters or return values in the operations of the invoked web service.
Update the method that contains the invoke of the web service to either throw or catch both java. The following sample build. This operation has a user-defined data type BasicStruct as both a parameter and a return value. The relevant code is shown in bold and described after the example. Follow these guidelines when programming the JWS file that invokes another web service; code snippets of the guidelines are shown in bold in the preceding example:.
Import any user-defined data types that are used by the invoked web service. Ensure that your client web service throws or catches ServiceException and RemoteException :. Invoke the echoComplexType operation of ComplexService using the port you just instantiated:.
If, however, your computer does not have WebLogic Server installed, you can still invoke a web service by using the standalone WebLogic web services client JAR file, as described in this section. The standalone client JAR file does not , however, support invoking web services that use the following advanced features:. To use the standalone WebLogic web services client JAR file with your client application, follow these steps:.
You can use a proxy server to proxy requests from a client application to an application server either WebLogic or non-WebLogic that hosts the invoked web service. You typically use a proxy server when the application server is behind a firewall. There are two ways to specify the proxy server in your client application: programmatically using the WebLogic HttpTransportInfo API or using system properties. You can programmatically specify within the Java client application itself the details of the proxy server that will proxy the web service invoke by using the standard java.
You use the java. The code in bold is described after the example:. The proxyHost and proxyPort arguments refer to the host computer and port of the proxy server. Create an HttpTransportInfo object and use the setProxy method to set the proxy server information:.
Use the weblogic. Use weblogic. To use system properties to specify the proxy server, write your client application in the standard way, and then specify system properties when you execute the client application. You have a choice of using standard Java system properties or historical WebLogic properties.
The following table summarizes the Java system properties. In this case, the proxySet system property must not be set. Name of the host computer on which the proxy server is running. Active 5 years, 9 months ago. Viewed 6k times. ClassNotFoundException: javax. ServiceException at java. Improve this question. Add a comment. Active Oldest Votes. Improve this answer. Steve C Steve C Thanks for the hint. Yes, I am using Kepler — micMike. Are you starting from a WSDL or from java classes?
When I use wsimport -keep my. Show 1 more comment. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown.
The Overflow Blog. Stack Gives Back Safety in numbers: crowdsourcing data on nefarious IP addresses.
0コメント