Service call, java calls webservice
Calling the cxf server using axis (version 1.4) has never been successful, so it took a long time to get bored. After google ~ Finally, let's talk about my code and solutions.
--- Use cxf integrated with bboss mvc as the ws Server
Jar packages required by axis: axis. jar, axis-ant.jar, commons-discovery-0.2.jar, commons-logging-1.0.4.jar, jaxrpc. jar, log4j-1.2.8.jar, saaj. jar, wsdl4j-1.5.1.jar
Interface code defined by Java cxf
- Import javax. jws. WebService;
- /**
- * <P> class description: XX Data Synchronization </p>
- * @ Author XX
- * @ Version 1.0
- * @ Date 2011-8-9 11:38:20 AM
- */
- @ WebService (name = "DataSynInf ")
- Public interface DataSynInf {
- /**
- * XXXXXXXXX
- * @ Param xml
- * @ Return
- */
- Public String synMaterialAndBom (String xml );
- }
Java axis caller code
- Public static void testDemo (){
- Try {
- String endpoint = "http: // 172.16.81.65: 8080/cxfservices/InterfacePort ";
- // Call Process
- Service service = new Service ();
- Call call = (Call) service. createCall ();
- Call. setTargetEndpointAddress (new java.net. URL (endpoint ));
- Call. setOperationName ("synMaterialAndBom"); // The operation name described in the WSDL
- Call. addParameter ("xml ",
- Org. apache. axis. encoding. XMLType. XSD_STRING,
- Javax. xml. rpc. ParameterMode. IN); // Operation Parameter
- Call. setReturnType (org. apache. axis. encoding. XMLType. XSD_STRING); // you can specify the return type.
- Call. setUseSOAPAction (true );
- // Pass parameters to the method and call the Method
- String temp = "good ";
- Object [] obj = new Object [] {temp };
- String result = (String) call. invoke (obj );
- System. out. println ("Result is:" + result );
- } Catch (Exception e ){
- E. printStackTrace ();
- }
- }