Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to invoke webservice instance by CXF dynamic client

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how the CXF dynamic client calls webservice examples, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Use CXF to implement WebService, and implement dynamic invocation on the client side to write server considerations

Note: do not specify

@ SOAPBinding (style=Style.RPC, use=Use.LITERAL) because cxf does not support: rpc, encoded, calling procedures in dynamic clients.

Cxf webservice development materials, online search is mostly similar, the same as the official example.

Are simple examples of static calls. There are few data and errors on dynamic invocation. Under the circumstances that I have been messed with.

It dawned on a buddy's blog http://hi.baidu.com/flierssp/item/2de0745c1afc1f3b32e0a96f that dynamic invocation does not support RPC.

Server side:

Package com.rodjson.cxf

Import javax.jws.WebMethod

Import javax.jws.WebParam

Import javax.jws.WebService

@ WebService

/ * @ SOAPBinding (style=Style.RPC, use=Use.LITERAL) Note: be sure to comment out this code if you want to call it dynamically * /

Public interface HelloWorld {

@ WebMethod

String sayHi (@ WebParam (name= "text") String text)

}

Package com.rodjson.cxf

-HelloWorldImpl

Import javax.jws.WebService

@ WebService (endpointInterface= "com.rodjson.cxf.HelloWorld"

ServiceName= "HelloWorld")

Public class HelloWorldImpl implements HelloWorld {

Public String sayHi (String text) {

System.out.println ("sayHi called")

Return "Hello" + text

}

}

Deployment:

Package com.rodjson.cxf

Import javax.xml.ws.Endpoint

Public class webServiceApp {

Public static void main (String [] args) {

System.out.println ("web service start")

HelloWorld implementor = new HelloWorldImpl ()

String address = "http://localhost:8080/helloWorld";

Endpoint.publish (address, implementor)

System.out.println ("web service end")

}

}

There are a lot of deployment methods on the Internet, so I won't mention it. The focus is on dynamic client calls and error identification.

Package com.rodjson.cxf

Import org.apache.cxf.endpoint.Client

Import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory

Public class ClientObj {

Public static void main (String [] args) {

JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance ()

Client client = factory.createClient ("http://localhost:8080/cxf/services/HelloWorld?wsdl");

Try {

Object [] obj = client.invoke ("sayHi", "xiao")

System.out.println ("resp:" + obj [0])

} catch (Exception e) {

/ / TODO Auto-generated catch block

E.printStackTrace ()

}

}

}

The error is as follows:

2012-5-23 20:53:34 org.apache.cxf.common.jaxb.JAXBUtils logGeneratedClassNames

Information: Created classes:

JavacTask: passive fil

Usage: javacTask

-help is used to list possible options

2012-5-23 20:53:34 org.apache.cxf.endpoint.dynamic.DynamicClientFactory createClient

Critical: Could not compile java files for http://127.0.0.1:9082/CrmWeb/services/CrmInterServer?wsdl.

These are all the contents of the article "how CXF dynamic clients call webservice instances". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report