cxf 클 라 이언 트 의 쓰기
One of the most common scenarios is that where you have a service which you may or not manage and this service has a WSDL. In this case you'll often want to generate a client from the WSDL. This provides you with a strongly typed interface by which to interact with the service. Once you've generated a client, typical usage of it will look like so:
HelloService service = new HelloService();
Hello client = service.getHelloHttpPort();
String result = client.sayHi("Joe");
The WSDL2Java tool will generate JAX-WS clients from your WSDL. You can run WSDL2java one of three ways:
For more in depth information read Developing a JAX-WS consumer or see the Hello World demos inside the distribution.
JAX-WS Proxy
Instead of using a wsdl2java-generated stub client directly, you can use Service.create to create Service instances, the following code illustrates this process:
import java.net.URL;
import javax.xml.ws.Service;
...
URL wsdlURL = new URL("http://localhost/hello?wsdl");
QName SERVICE_NAME = new QName("http://apache.org/hello_world_soap_http", "SOAPService");
Service service = Service.create(wsdlURL, SERVICE_NAME);
Greeter client = service.getPort(Greeter.class);
String result = client.greetMe("test");
JAX-WS Dispatch APIs
JAX-WS provides the "dispatch" mechanism which makes it easy to dynamically invoke services which you have not generated a client for. Using the Dispatch mechanism you can create messages (which can be JAXB objects, Source objects, or a SAAJMessage) and dispatch them to the server. A simple example might look like this:
import java.net.URL;
import javax.xml.transform.Source;
import javax.xml.ws.Dispatch;
import javax.xml.ws.Service;
...
URL wsdlURL = new URL("http://localhost/hello?wsdl");
Service service = Service.create(wsdlURL, new QName("HelloService"));
Dispatch<Source> disp = service.createDispatch(new QName("HelloPort"), Source.class, Service.Mode.PAYLOAD);
Source request = new StreamSource("<hello/>")
Source response = disp.invoke(request);
NOTE: you can also use dispatches without a WSDL.
For more in depth information see the Hello World demos inside the distribution.
Simple Frontend Client Proxy
If you've developed a service using the simple frontend, you can use the ClientProxyFactoryBean API to create a Java proxy client for your service. This way you can use the service interface to talk to your service. For more information see the Simple Frontend documentation.
Dynamic Client
CXF includes a Client interface which allows you to invoke operations and pass parameters for those operations. For instance:
Client client = ....;
Object[] result = client.invoke("sayHi", "Dan");
There are two ways to create Clients at runtime. The first would be through the ClientFactoryBean and JaxWsClientFactoryBean classes. The second is through the DynamicClientFactory. The DynamicClientFactory goes the additional step of generating and compiling JAXB POJOs in the background for use at runtime via reflection. This is most useful when you're using a dynamic language such as Groovy with CXF.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Windows에서 CodeArtifact(Maven)용 토큰을 자동으로 생성하는 방법CodeArtifact를 사용한 적이 있거나 사용할 계획이라면 매일 모든 Maven 프로젝트에서 수동으로 토큰(CODEARTIFACT_AUTH_TOKEN)을 생성해야 합니다. 이는 어려울 수 있으며 개발 속도를 늦출...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.