You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Joe Sunday <su...@csh.rit.edu> on 2007/08/31 04:50:42 UTC

Client question

Sorry if this one is easy, but I can't seem to find it...

I've got an interface I generated from a local wsdl, and the wsdl  
files are both available on my classpath:
<definitions targetNamespace="urn:myService"
    xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:interface="urn:service2">
    <import location="service2.wsdl" namespace="urn:service2" />
    <service name="MyService">
       <port binding="interface:ServiceBinding" name="ServicePort">
          <soap:address location="https://localhost/sdk/myService" />

How do I create a client for this wsdl against a random url? The  
binding classes seem to only accept the urn and address specified in  
the wsdl, which doesn't work if the url I actually want to talk to  
isn't localhost/sdk/myService

     URL wsdlURL = MyService.class.getClassLoader.getResource 
("myService.wsdl");
   QName serviceName = new QName("urn:myService", "MyService");
   MyService service = new MyService(wsdlURL, serviceName);
   ServicePort client = service.getServicePort();

I don't see a generated ServiceLocator in the classes wsdl2java  
generated anywhere.

--Joe


Re: Client question

Posted by Freeman Fang <fr...@iona.com>.
Hi Joe,

You can create client from JaxWsProxyFactoryBean and set a random url, 
the code is as follows
        JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
        poxyFactory.setServiceClass(ServicePort.class);
        proxyFactory.setAddress("theUrlyouwant");
       ServicePort client = (ServicePort) proxyFactory.create();
Best Regards
Freeman
Joe Sunday wrote:
> Sorry if this one is easy, but I can't seem to find it...
>
> I've got an interface I generated from a local wsdl, and the wsdl 
> files are both available on my classpath:
> <definitions targetNamespace="urn:myService"
>    xmlns="http://schemas.xmlsoap.org/wsdl/"
>    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
>    xmlns:interface="urn:service2">
>    <import location="service2.wsdl" namespace="urn:service2" />
>    <service name="MyService">
>       <port binding="interface:ServiceBinding" name="ServicePort">
>          <soap:address location="https://localhost/sdk/myService" />
>
> How do I create a client for this wsdl against a random url? The 
> binding classes seem to only accept the urn and address specified in 
> the wsdl, which doesn't work if the url I actually want to talk to 
> isn't localhost/sdk/myService
>
>     URL wsdlURL = 
> MyService.class.getClassLoader.getResource("myService.wsdl");
>   QName serviceName = new QName("urn:myService", "MyService");
>   MyService service = new MyService(wsdlURL, serviceName);
>   ServicePort client = service.getServicePort();
>
> I don't see a generated ServiceLocator in the classes wsdl2java 
> generated anywhere.
>
> --Joe
>
>

Re: Client question

Posted by Daniel Kulp <dk...@apache.org>.
And to give you yet a third option....   :-)


URL wsdlURL = MyService.class.getClassLoader
            .getResource ("myService.wsdl");
QName serviceName = new QName("urn:myService", "MyService");
MyService service = new MyService(wsdlURL, serviceName);
ServicePort client = service.getServicePort();
BindingProvider provider = (BindingProvider)client;
provider.getRequestContext().put(
      BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
      "https://my/new/url/to/the/service");

Again, completely JAX-WS compliant code.

Enjoy!
Dan



On Thursday 30 August 2007, Joe Sunday wrote:
> Sorry if this one is easy, but I can't seem to find it...
>
> I've got an interface I generated from a local wsdl, and the wsdl
> files are both available on my classpath:
> <definitions targetNamespace="urn:myService"
>     xmlns="http://schemas.xmlsoap.org/wsdl/"
>     xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
>     xmlns:interface="urn:service2">
>     <import location="service2.wsdl" namespace="urn:service2" />
>     <service name="MyService">
>        <port binding="interface:ServiceBinding" name="ServicePort">
>           <soap:address location="https://localhost/sdk/myService" />
>
> How do I create a client for this wsdl against a random url? The
> binding classes seem to only accept the urn and address specified in
> the wsdl, which doesn't work if the url I actually want to talk to
> isn't localhost/sdk/myService
>
>      URL wsdlURL = MyService.class.getClassLoader.getResource
> ("myService.wsdl");
>    QName serviceName = new QName("urn:myService", "MyService");
>    MyService service = new MyService(wsdlURL, serviceName);
>    ServicePort client = service.getServicePort();
>
> I don't see a generated ServiceLocator in the classes wsdl2java
> generated anywhere.
>
> --Joe



-- 
J. Daniel Kulp
Principal Engineer
IONA
P: 781-902-8727    C: 508-380-7194
daniel.kulp@iona.com
http://www.dankulp.com/blog

Re: Client question

Posted by Willem Jiang <ni...@iona.com>.
Hi,

If you use JAXWS API , you can using the add port to add the other port 
for your client to access.
URL wsdlURL = MyService.class.getClassLoader.getResource("service2.wsdl");
  QName serviceName = new QName("urn:service2", "MyService");
  QName portName = new QName("urn:service2", "ServicePort");
  MyService service = new MyService(wsdlURL, serviceName);
  service.addPort(portName, "http://schemas.xmlsoap.org/soap/", 
"https://localhost/sdk/myService");
  //   pass the SEI class that is generated by wsdl2java     
  ServicePort proxy = service.getPort(portName, SEI.class);

If you use CXF API , you could set the endpoint address directly to the 
ClientProxyFactoryBean.

BTW, if you want to access the service by using https protocol, you need 
to do some configuration on the client side.

You can find more information from this url [1]
[1]http://www.nabble.com/Generated-client-to-connect-to-a-https-ws-tf4061903.html

Willem.


Joe Sunday wrote:
> Sorry if this one is easy, but I can't seem to find it...
>
> I've got an interface I generated from a local wsdl, and the wsdl 
> files are both available on my classpath:
> <definitions targetNamespace="urn:myService"
>    xmlns="http://schemas.xmlsoap.org/wsdl/"
>    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
>    xmlns:interface="urn:service2">
>    <import location="service2.wsdl" namespace="urn:service2" />
>    <service name="MyService">
>       <port binding="interface:ServiceBinding" name="ServicePort">
>          <soap:address location="https://localhost/sdk/myService" />
>
> How do I create a client for this wsdl against a random url? The 
> binding classes seem to only accept the urn and address specified in 
> the wsdl, which doesn't work if the url I actually want to talk to 
> isn't localhost/sdk/myService
>
>     URL wsdlURL = 
> MyService.class.getClassLoader.getResource("myService.wsdl");
>   QName serviceName = new QName("urn:myService", "MyService");
>   MyService service = new MyService(wsdlURL, serviceName);
>   ServicePort client = service.getServicePort();
>
> I don't see a generated ServiceLocator in the classes wsdl2java 
> generated anywhere.
>
> --Joe
>
>