10

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.

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:

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?

4

4 回答 4

20

有几种方法,我会告诉你两种:

  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");
    

    您可以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);
    
于 2013-11-07T03:23:32.247 回答
5

最后我使用了 CXF 库,我实现了使用 Paul Vargas 的答案:

没有 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);

使用标准的jaw-ws,这个解决方案不起作用,CXF 是必要的。

于 2013-12-23T08:51:56.423 回答
1

我也需要这样的东西。

就我而言,我在我的 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");
于 2014-09-15T19:25:56.417 回答
0

当您的 xml 中存在解析错误并且指定的行和列有问题时,会发生此异常。检查你的xml

于 2013-11-06T18:35:44.100 回答