Java Reference
In-Depth Information
project in NetBeans. To do so, click File→New Project→Samples→Web Service→Cal-
culator. Of course, you can use any project you like. Doing so will also create a Calculator
Client project, containing a web service reference.
When the client project was created, it imported a copy of the WSDL from the service.
This is the copy you need to change to point to TCPMon. To access the WSDL, navigate
to Configuration Files→xml-resources→web-service-references, and find the WSDL un-
der it. If you're using a different web service client project, just locate the local copy of
the WSDL that is being invoked. Find this section at the end of the WSDL file:
<soap:address location="http://localhost:8080/CalculatorApp/
CalculatorWSService">
Change the location to http://localhost:8090/CalculatorApp/CalculatorWSSer-
vice .
4. Now you need to change your application to use the modified WSDL. If you're using
the
NetBeans
sample,
find
the
ClientServlet Java
source
file
in
the
org.me.calculator.client package. Find this line:
@WebServiceRef(wsdlLocation =
"http://localhost:8080/CalculatorApp/CalculatorWSService?wsdl")
Modify it to use the TCPMon port number of 8090. Because you're in a servlet, the con-
tainer will inject the service instance at runtime, and use the modified WSDL location.
If you weren't using a servlet, but had generated portable artifacts from wsimport , you
could use code similar to this:
URL wsdlLocation = new URL("file:///C:/projects/etc/
CalculatorWSService.wsdl");
QName serviceName = new QName("http://calculator.me.org/
",
"CalculatorWSService");
CalculatorWSService service =
new CalculatorWSService(wsdlLocation, serviceName);
CalculatorWS port = service.getCalculatorWSPort();
int result = port.add(2, 3);
The thing that you're doing here is overriding the WSDL that the client will use when in-
voking the service; you're pointing to the file that you've modified manually.
5. Now you'll make a request, routed through the monitor. If necessary, clean and build
the web service Calculator project, and make sure it is deployed using the Undeploy and
Deploy target.
Now right-click on the web service Calculator Client project and choose Run.
Search WWH ::




Custom Search