Java 没有 WSDL 文档文件的 JAX-WS 客户端
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19815145/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JAX-WS client without a WSDL document file
提问by mls_dev
I am consuming a webservice soa, with netbeans (jax-ws) i use netbeans auto generate client, and all run fine, but i see that the wsdl is always downloading while the client is running.
我正在使用 webservice soa,使用 netbeans (jax-ws) 我使用 netbeans 自动生成客户端,并且一切运行良好,但我看到 wsdl 在客户端运行时总是在下载。
In production i don't want expose the wsdl, and i am trying to modify the client for don't require wsdl, all my intends are wrong, i find this:
在生产中,我不想公开 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");
but when the first line is executed i found this exception:
但是当第一行执行时,我发现了这个异常:
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)
Any idea to ignore wsdl?
有什么想法可以忽略 wsdl?
采纳答案by mls_dev
Finally i use the CXF libraries and i achieve use the Paul Vargas answer:
最后,我使用 CXF 库,并使用 Paul Vargas 回答:
Without a WSDL document file
This solution requires the client generated.
没有 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);
Using standard jaw-ws, this solution don't work, CXF is necessary.
使用标准的jaw-ws,这个解决方案不起作用,CXF 是必要的。
回答by constantlearner
This exception happens while there is a parse error in your xml and there is something wrong at the specified row and column. Check your xml
当您的 xml 中存在解析错误并且指定的行和列有问题时,会发生此异常。检查你的 xml
回答by Paul Vargas
There are several ways, of which I will tell you two:
有几种方法,我告诉你两种:
Use a WSDL document file locally
Save a copy of the WSDL document file and the schemma files to your project.
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");
You may combinethe WSDL document file with the schema files.
Without a WSDL document file
This solution requires the client generated.
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);
在本地使用 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");
没有 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);
回答by Hymanson Cassimiro
I needed something like this, too.
我也需要这样的东西。
In my case, I had put a dummy wsdl without endpoint address inside my web app classpath. After that, I set a valid address at runtime, like this:
就我而言,我在我的 Web 应用程序类路径中放置了一个没有端点地址的虚拟 wsdl。之后,我在运行时设置了一个有效地址,如下所示:
String WSDL = "/config/ws/Main_default.wsdl";
Main service = new Main(Main.class.getResource(WSDL), new QName(
"http://www.example.com/", "Main"));
MainWS port = service.getMainWSPort();
BindingProvider bindingProvider = (BindingProvider) port;
bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
"http://app.example.com/ws/services/main");
Object result = port.someMethod("some param");