我正在使用 netbeans (jax-ws) 的 web 服务 soa 我使用 netbeans 自动生成客户端,并且一切运行良好,但我看到 wsdl 总是在客户端运行时下载。
在生产中我不想公开 wsdl,我正在尝试修改客户端不需要 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");
但是当第一行执行时我发现了这个异常:
Message: El contenido no está permitido en el prólogo.
at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.wrapException(Unknown Source)
at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.next(Unknown Source)
at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.nextContent(Unknown Source)
at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.nextElementContent(Unknown Source)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.hasWSDLDefinitions(Unknown Source)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(Unknown Source)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(Unknown Source)
at javax.xml.ws.Service.<init>(Unknown Source)
有什么想法可以忽略 wsdl 吗?
最佳答案
方法有很多种,我给大家说两种:
在本地使用 WSDL 文档文件
将 WSDL 文档文件和架构文件的副本保存到您的项目中。
ClassLoader classloader = Thread.currentThread().getContextClassLoader(); URL wsdlLocation = classloader.getResource("MyHelloService.wsdl"); QName serviceName= new QName("http://test.com/", "MyHelloService"); MyHelloService service = new MyHelloService(wsdlLocation, serviceName); service.sayHello("Test");
您可以 combine带有架构文件的 WSDL 文档文件。
没有 WSDL 文档文件
此解决方案需要生成客户端。
QName qname = new QName("http://thenamespace", "FooService"); FooService service = new FooService(null, qname); // null for ignore WSDL Foo port = service.getFooPort(); BindingProvider bindingProvider = (BindingProvider) port; bindingProvider.getRequestContext() .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://foo.com/soap/fooBean"); // Use the service String result = port.doSomething(param);
关于java - 没有 WSDL 文档文件的 JAX-WS 客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19815145/