0

设想

我在 .NET (WCF) 中创建了 Web 服务,并且我必须将 Java Swing 用于客户端应用程序。

环境

网豆 7.2

JAVA代码:

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

输出:

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)

请帮忙!我不是 java 专业人士,所以请让我了解问题所在以及如何解决问题。我已经“用谷歌搜索”了,但在这方面没有找到太多。有任何想法吗?

编辑: 用 Soap UI 得到这个。不确定解决方案是什么,因为我没有为它设置任何类型的身份验证:

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

编辑2:

好的,伙计们..我明白了..基本上解决方法是我必须将 WCF 服务从 using 更改wsHttpBindingbasicHttpBinding. 似乎他们使用不同版本的 SOAP 规范。希望这对其他人有帮助。我稍后会将其添加为答案,但 StackOverflow 不会让我再过 8 小时回答我自己的问题,因为我的声望不到 10。如果有人可以对此帖子进行投票,那么我将立即添加答案。:-)

4

1 回答 1

0

我明白了.. 基本上解决方法是我必须将 WCF 服务从使用 wsHttpBinding 更改为 basicHttpBinding。似乎他们使用不同版本的 SOAP 规范。希望这对其他人有帮助。

于 2013-03-01T13:39:48.847 回答