java - 没有 WSDL 文档文件的 JAX-WS 客户端

标签 java web-services netbeans client jax-ws

我正在使用 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 吗?

最佳答案

方法有很多种,我给大家说两种:

  1. 在本地使用 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 文档文件。

  2. 没有 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/

相关文章:

c# - Linux 上的 .Net Web 服务

java - Clojure deftype : how to constrain field types?

java - 在 Java 中将大量对象存储到磁盘的最佳方法

java - Jax Ws 与 PHP 客户端始终发送 Null parm

java - 修改SoapHandler中的Soap header

c++ - NetBeans 有 C 自动注释吗?

java - spring boot不加载jsp文件

java - 字符串长度和字符串子串方法之间有什么关系?

java - 无法将图像资源导入我们的 GUI

java - 使用 Windows 的 NetBeans 中忽略的最大内存大小