简体   繁体   中英

Java Web Services: Getting HTTP 400 with generated client code in simple app

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. :-)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM