Service call, java calls webservice

Source: Internet
Author: User

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

  1. Import javax. jws. WebService;
  2. /**
  3. * <P> class description: XX Data Synchronization </p>
  4. * @ Author XX
  5. * @ Version 1.0
  6. * @ Date 2011-8-9 11:38:20 AM
  7. */
  8. @ WebService (name = "DataSynInf ")
  9. Public interface DataSynInf {
  10. /**
  11. * XXXXXXXXX
  12. * @ Param xml
  13. * @ Return
  14. */
  15. Public String synMaterialAndBom (String xml );
  16. }

Java axis caller code
  1. Public static void testDemo (){
  2. Try {
  3. String endpoint = "http: // 172.16.81.65: 8080/cxfservices/InterfacePort ";
  4. // Call Process
  5. Service service = new Service ();
  6. Call call = (Call) service. createCall ();
  7. Call. setTargetEndpointAddress (new java.net. URL (endpoint ));
  8. Call. setOperationName ("synMaterialAndBom"); // The operation name described in the WSDL
  9. Call. addParameter ("xml ",
  10. Org. apache. axis. encoding. XMLType. XSD_STRING,
  11. Javax. xml. rpc. ParameterMode. IN); // Operation Parameter
  12. Call. setReturnType (org. apache. axis. encoding. XMLType. XSD_STRING); // you can specify the return type.
  13. Call. setUseSOAPAction (true );
  14. // Pass parameters to the method and call the Method
  15. String temp = "good ";
  16. Object [] obj = new Object [] {temp };
  17. String result = (String) call. invoke (obj );
  18. System. out. println ("Result is:" + result );
  19. } Catch (Exception e ){
  20. E. printStackTrace ();
  21. }
  22. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.