JAX-WS client without a WSDL document file

后端 未结 4 954
醉酒成梦
醉酒成梦 2020-12-09 06:25

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

相关标签:
4条回答
  • 2020-12-09 06:32

    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:

        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");
    
    0 讨论(0)
  • 2020-12-09 06:34

    There are several ways, of which I will tell you two:

    1. 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 combine the WSDL document file with the schema files.

    2. 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);
      
    0 讨论(0)
  • 2020-12-09 06:34

    Finally i use the CXF libraries and i achieve use the Paul Vargas answer:

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

    Using standard jaw-ws, this solution don't work, CXF is necessary.

    0 讨论(0)
  • 2020-12-09 06:52

    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

    0 讨论(0)
提交回复
热议问题