Мгновенный запуск службы JAX-WS без загрузки WSDL?
У меня есть веб-служба, у которой JAX-WS создаются клиентские привязки, как показано ниже:
// web service client generated by JAX-WS
@WebServiceClient( ... )
public class WebService_Service extends Service {
public WebService_Service(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
WebService getWebServiceSOAP() {
// ...
}
}
Я хочу создать экземпляр этого объекта, который указывает на удаленный сервис, например:
WebService_Service svc = new WebService_Service(
new URL("http://www.example.com/ws?wsdl"),
new QName("http://www.example.com/ws", "WebService"));
Но это загружает WSDL из http://www.example.com/ws?wsdl
, который я не хочу делать.
Есть ли способ остановить загрузку этого WSDL, но все же указать на ту же конечную точку?
Ответы
Ответ 1
Я решил это, указав null для URL WSDL на клиенте, а также явно указав адрес конечной точки:
WebService_Service svc = new WebService_Service(
null,
new QName("http://www.example.com/ws", "WebService"));
WebService port = svc.getPort(WebService.class);
BindingProvider bindingProvider = (BindingProvider) port;
bindingProvider.getRequestContext()
.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
"http://www.example.com/real_endpoint_url_goes_here");
См:
http://shrubbery.homeip.net/c/display/W/Consuming+a+Web+Service+with+Java+6+and+JAX-WS#ConsumingaWebServicewithJava6andJAX-WS-IgnoringtheWSDLCompletely
Ответ 2
У меня была та же проблема, и я решил это, но я не могу раскрыть ее с вашим образцом, потому что это зависит от wsdl.
Вот мой код, отслеживайте решение:
//This is the input object for the webservice
GetDocumentInfoInput input = new GetDocumentInfoInput();
input.setBarcode(barcode);
//I instantiate the WS
MAKSpcIntSpcWFSpcScannerInfo_Service service = new MAKSpcIntSpcWFSpcScannerInfo_Service();
//I get the WS port
MAKSpcIntSpcWFSpcScannerInfo port = service.getMAKSpcIntSpcWFSpcScannerInfo();
WSBindingProvider provider = (WSBindingProvider)port;
//This is the row what set the URL for the WS
provider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
//This is the WS calling
GetDocumentInfoOutput output = port.getDocumentInfo(input);
Ответ 3
Файлы WSDL могут содержать параметры конфигурации, которые сгенерированные заглушки не содержат, поэтому они необходимы во время выполнения. Вы можете предоставить их локально в своем пути к классу.
Следующий maven pom.xml работал у меня после размещения WSDL файлов службы, которую я использую в моей папке ${basedir}\src\main\resources\META-INF\wsdl
:
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>MyService</id>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<!-- this resolves naming conflicts within the wsdl - there are several copies of fault report objects which clash otherwise. -->
<args>
<arg>-B-XautoNameResolution</arg>
</args>
<packageName>de.xyz</packageName>
<wsdlDirectory>${basedir}\src\main\resources\META-INF\wsdl</wsdlDirectory>
<wsdlFiles>
<wsdlFile>MyService.wsdl</wsdlFile>
</wsdlFiles>
<wsdlLocation>META-INF/wsdl/MyService.wsdl</wsdlLocation>
</configuration>
</execution>
[...]
Во время выполнения файлы wsdl будут загружены из пути к классу.