0

SCENARIO

I created the web service in .NET (WCF) and I have to use Java Swing for the client app.

ENVIRONMENT

Netbeans 7.2

JAVA CODE:

BookingService service;
    List<Booking> bookings;

    /**
     * Creates new form Home
     */
    public Home() {
        initComponents();
        service = new BookingService();
        refresh();
    }

    private void refresh() {
        DefaultTableModel model = (DefaultTableModel)grid.getModel();
        model.setRowCount(0);

        bookings = getAll().getBooking(); // breaks at this line
        if (bookings != null && !bookings.isEmpty()) {
            grid.getColumnModel().getColumn(0).setMinWidth(50);
            grid.getColumnModel().getColumn(0).setMaxWidth(50);
            grid.getColumnModel().getColumn(1).setMinWidth(150);
            grid.getColumnModel().getColumn(1).setMaxWidth(150);
            for (int i = 0; i < bookings.size(); i++) {
                Booking item = bookings.get(i);
                Object[] rowData = new Object[] {
                    item.getId(),
                    item.getCustomerId(),
                    item.getActivityId(),
                    item.getBookingDate(),
                    item.getStartTime(),
                    item.getEndTime()
                };
                model.addRow(rowData);
            }
        }
    }

//etc

private static ArrayOfBooking getAll() {
        racquetandhealthclient.services.bookings.BookingService service = new racquetandhealthclient.services.bookings.BookingService();
        racquetandhealthclient.services.bookings.IBookingService port = service.getWSHttpBindingIBookingService();
        return port.getAll();
    }

OUTPUT:

ant -f C:\\Users\\Matt\\Documents\\NetBeansProjects\\RacquetAndHealthClient -Ddebug.class=racquetandhealthclient.Program debug
init:
Deleting: C:\Users\Matt\Documents\NetBeansProjects\RacquetAndHealthClient\build\built-jar.properties
deps-jar:
Updating property file: C:\Users\Matt\Documents\NetBeansProjects\RacquetAndHealthClient\build\built-jar.properties
wsimport-init:
wsimport-client-activities:
files are up to date
wsimport-client-bookings:
files are up to date
wsimport-client-charge-accounts:
files are up to date
wsimport-client-countries:
files are up to date
wsimport-client-customers:
files are up to date
wsimport-client-invoices:
files are up to date
wsimport-client-generate:
compile:
Mar 01, 2013 9:42:56 AM [com.sun.xml.internal.ws.policy.EffectiveAlternativeSelector]  selectAlternatives
WARNING: WSP0075: Policy assertion "{http://schemas.xmlsoap.org/ws/2005/07/securitypolicy}SymmetricBinding" was evaluated as "UNKNOWN".
Mar 01, 2013 9:42:56 AM [com.sun.xml.internal.ws.policy.EffectiveAlternativeSelector]  selectAlternatives
WARNING: WSP0075: Policy assertion "{http://schemas.xmlsoap.org/ws/2005/07/securitypolicy}Trust10" was evaluated as "UNKNOWN".
Mar 01, 2013 9:42:56 AM [com.sun.xml.internal.ws.policy.EffectiveAlternativeSelector]  selectAlternatives
WARNING: WSP0075: Policy assertion "{http://schemas.xmlsoap.org/ws/2005/07/securitypolicy}Wss11" was evaluated as "UNKNOWN".
Mar 01, 2013 9:42:56 AM [com.sun.xml.internal.ws.policy.EffectiveAlternativeSelector]  selectAlternatives
WARNING: WSP0075: Policy assertion "{http://www.w3.org/2006/05/addressing/wsdl}UsingAddressing" was evaluated as "UNKNOWN".

//ETC.... same as above lines about 30 times... then:

Exception in thread "AWT-EventQueue-0" com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 400: Bad Request
    at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.checkStatusCode(HttpTransportPipe.java:278)
    at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.createResponsePacket(HttpTransportPipe.java:245)
    at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:203)
    at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:122)
    at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:123)
    at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:626)
    at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:585)
    at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:570)
    at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:467)
    at com.sun.xml.internal.ws.client.Stub.process(Stub.java:308)
    at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:146)
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:98)
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
    at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:129)
    at $Proxy31.getAll(Unknown Source)
    at racquetandhealthclient.views.bookings.Home.getAll(Home.java:94)
    at racquetandhealthclient.views.bookings.Home.refresh(Home.java:35)
    at racquetandhealthclient.views.bookings.Home.<init>(Home.java:28)
    at racquetandhealthclient.Program$1.run(Program.java:38)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:721)
    at java.awt.EventQueue.access$200(EventQueue.java:103)
    at java.awt.EventQueue$3.run(EventQueue.java:682)
    at java.awt.EventQueue$3.run(EventQueue.java:680)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:691)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
debug:
BUILD SUCCESSFUL (total time: 1 minute 26 seconds)

Please help! I am not a java pro, so please make it simple for me to understand what's wrong and how to fix it. I've 'googled' around, but not found much on this. Any ideas?

EDIT: Got this with Soap UI. Not sure what the solution is though, because I did not set any kind of authentication for it:

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
   <s:Header>
      <a:Action s:mustUnderstand="1">http://www.w3.org/2005/08/addressing/soap/fault</a:Action>
   </s:Header>
   <s:Body>
      <s:Fault>
         <s:Code>
            <s:Value>s:Sender</s:Value>
            <s:Subcode>
               <s:Value xmlns:a="http://schemas.xmlsoap.org/ws/2005/02/sc">a:BadContextToken</s:Value>
            </s:Subcode>
         </s:Code>
         <s:Reason>
            <s:Text xml:lang="en-US">The message could not be processed. This is most likely because the action 'http://tempuri.org/IBookingService/GetAll' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.</s:Text>
         </s:Reason>
      </s:Fault>
   </s:Body>
</s:Envelope>

EDIT 2:

OK Guys.. I've got it.. basically the fix was that I had to change the WCF service from using wsHttpBinding to basicHttpBinding. It seems they use different versions of the SOAP specification. Hope this helps others. I will add it as answer later, but StackOverflow won't let me answer my own question for another 8 hours because I have less than 10 reputation. If someone can upvote this post, then I will add the answer immediately. :-)

Matt
  • 6,787
  • 11
  • 65
  • 112
  • can u hit the webserive through Internet Explorer ? – user1428716 Mar 01 '13 at 03:05
  • yes, it works fine and by the way; there's no authentication needed either in case anyone is wondering. – Matt Mar 01 '13 at 03:08
  • whr r u setting the endpoint ? – user1428716 Mar 01 '13 at 03:11
  • @Matt it seems like problem with inputs you passed to service..Try to invoke by client like soap.. then use the same inputs in your UI or java – NaveenKumar1410 Mar 01 '13 at 03:15
  • @Boss, I'm not sure what you mean.. that code was generated by Netbeans for me and also the getAll() method does not take any input parameters. I'm completely new to this, if what I have done is not right, can you give me an example of how to fix it? – Matt Mar 01 '13 at 03:23
  • @user1428716, the web service is running on my localhost and I see the wsdl which netbeans downloaded has the correct URL in it. – Matt Mar 01 '13 at 03:25
  • Can u hit the webservie using SoapUI ? – user1428716 Mar 01 '13 at 03:27
  • @user1428716, I also see this in the BookingService class: `url = new URL("http://localhost:8000/RacquetAndHealthClub/service/bookings.svc?singleWsdl");`. Is that what you wanted to see? – Matt Mar 01 '13 at 03:28
  • ok .. thats fine .. use SOAPUI setting same kind of data and see if u get the same error .. Also in IE http://localhost:8000/RacquetAndHealthClub/service/bookings.svc?wsdl and not singleWsdl – user1428716 Mar 01 '13 at 03:29
  • I just found this: http://stackoverflow.com/questions/7205801/consuming-a-wcf-service-in-a-java-client-using-wshttpbinding.. maybe I'm better off trying to use a traditional .asmx style web service?? – Matt Mar 01 '13 at 03:47

1 Answers1

0

I've got it.. basically the fix was that I had to change the WCF service from using wsHttpBinding to basicHttpBinding. It seems they use different versions of the SOAP specification. Hope this helps others.

Matt
  • 6,787
  • 11
  • 65
  • 112