1 2 Previous Next 20 Replies Latest reply on Jan 14, 2008 5:07 PM by mjhammel Go to original post
      • 15. Re: Writing a client - no examples for BindingProvider based
        mjhammel

         

        "jeff norton" wrote:
        I use the same wsprovide and wsconsume targets that you do, but the client still seems to need the WSDL in order to create the service endpoint.


        My client doesn't call Service.create() directly. Instead, I reference the client side classes generated by wsconsume:

        SubscriberServicesService service = new SubscriberServicesService();
         ss = service.getSubscriberWSPort();
        
         /* Set NEW Endpoint Location */
         BindingProvider bp = (BindingProvider)ss;
         bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, crunchServer);
        
         /* Setup to authenticate with the server. */
         bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, subscriberID);
         bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, pw);


        The SubscriberServicesService class is one of the classes created by wsconsume. In it you'll find a hard coded path to the WSDL file created by wsprovide. However, this class also has a constructor that can change the location of this file. So when you package your client for use by end users you include the WSDL file generated by wsprovide and reference it's installed location when you do:

        SubscriberServicesService service = new SubscriberServicesService("installedLocation/WSDLfile", qname);

        My problem is I still don't know what a qname is so I'm not sure how to figure that out at run time so I can update the WSDL location in this manner.

        • 16. Re: Writing a client - no examples for BindingProvider based
          jbn1v

          Aha. I see from your example that I need to supply the target endpoint address explicitly (arg! these things need to be documented). That was what I was missing. Now I can get the case where I supply the WSDL as a file to work. However that doesn't do me a lot of good as I cannot use a hard-coded path. I would really like to put it in the WAR but I don't know how to create a URL that references things in the WAR (is there a way?). I could explicitly deploy the WSDL file into somewhere like $JBOSS_DIR/server/default/deploy/foo.wsdl but I don't really have a $JBOSS_DIR variable available at runtime. I guess I could set a property that would point to it.

          As for getting the QName, do you have an @WebService annotation in your generated client service class (e.g. SubscriberServicesService)? If you do, it should have name and targetNamespace parameters. You should be able to form a QName using the values of those parameters as:

          new QName(targetNamespace, name)

          The no arg public constructor should also have an example of it. Hope that helps.

          • 17. Re: Writing a client - no examples for BindingProvider based
            mjhammel

            You can override the hard coded path set in this class. I'm assuming you're writing a remote client, re: one that doesn't live on the same host as the Web Services server. In that case, you're packaging of the remote client just installs the WSDL file under a directory relative to the application file. At runtime of the client you find out where you're installed and generate the runtime location of the WSDL file from that. That way you don't have to ask the server for the WSDL information at startup time.

            As for getting the QName, do you have an @WebService annotation in your generated client service class (e.g. SubscriberServicesService)? If you do, it should have name and targetNamespace parameters.


            Oh sure, they're there. But how do I reference parameters in an annotation directly from my java code? The reference is in SubscriberServicesService.java and looks like this:

            @WebServiceClient(name = "SubscriberServicesService", targetNamespace = "http://SubscriberServices.ws.server.crunch.cei.com/",
            wsdlLocation = "file:/home/mjhammel/src/cei/crunch/build/server/resources/SubscriberServicesService.wsdl")
            

            or if you prefer, in the SubscriberServicesEndpoint.java:

            @WebService(name = "SubscriberServicesEndpoint", targetNamespace = "http://SubscriberServices.ws.server.crunch.cei.com/")
            public interface SubscriberServicesEndpoint {


            But how do I reference these parameters from my client code that instantiates the SubscriberServicesService class? Something like the following doesn't appear to work and there are not getters for these values either:

            SubscriberServicesService service = new SubscriberServicesService();
            System.out.println(ss.targetNamespace);





            • 18. Re: Writing a client - no examples for BindingProvider based
              jbn1v

              Annotations are available at runtime only if the annotation is declared to provide runtime visibility. Fortunately the WebServiceClient is so you should be able to do the following (it works for me):

              SubscriberServicesService a = SubscriberServicesService.class.getAnnotation(SubscriberServicesService.class);
              new QName(a.targetNamespace(), a.name());
              


              • 19. Re: Writing a client - no examples for BindingProvider based
                jbn1v

                Oops. Sorry (cut and paste error). Code should be:

                WebServiceClient a = SubscriberServicesService.class.getAnnotation(WebServiceClient.class);
                QName serviceName = new QName(a.targetNamespace(), a.name());


                • 20. Re: Writing a client - no examples for BindingProvider based
                  mjhammel

                  Indeed it does. Thanks. That's a cool trick. And it means it will be easy to override the hard coded path to the WSDL filename when the time comes (I'm a ways away from having to package my client, however).

                  1 2 Previous Next