在Netbeans 7.1中使用Java + Metro客户端使用wcf Web服务时出错

时间:2012-03-27 12:51:32

标签: java wcf-security webservice-client netbeans-7 java-metro-framework

我正在尝试使用https secure wcf web service using username and password凭据,.Net client可以执行相同的工作。

我有什么,我正在使用Netbeans 7.1,Metro 2和Glassfish3

我有一个wsdl,并且通过使用该wsdl,我能够generate the Java stubs,但是当我运行客户端时,它会抛出下面的exception

com.sun.xml.ws.fault.ServerSOAPFaultException: Client received SOAP Fault from server: An error occurred when verifying security for the message. Please see the server log to find more detail regarding exact cuase of the failure.

这是来自wsdl

政策部分
<wsp:Policy wsu:Id="CustomBinding_IStandardApi_policy">
        <wsp:ExactlyOne>
            <wsp:All>
                <sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
                    <wsp:Policy>
                        <sp:TransportToken>
                            <wsp:Policy>
                                <sp:HttpsToken RequireClientCertificate="false"/>
                            </wsp:Policy>
                        </sp:TransportToken>
                        <sp:AlgorithmSuite>
                            <wsp:Policy>
                                <sp:Basic256/>
                            </wsp:Policy>
                        </sp:AlgorithmSuite>
                        <sp:Layout>
                            <wsp:Policy>
                                <sp:Strict/>
                            </wsp:Policy>
                        </sp:Layout>
                        <sp:IncludeTimestamp/>
                    </wsp:Policy>
                </sp:TransportBinding>
                <sp:SignedSupportingTokens xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
                    <wsp:Policy>
                        <sp:UsernameToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
                            <wsp:Policy>
                                <sp:WssUsernameToken10/>
                            </wsp:Policy>
                        </sp:UsernameToken>
                    </wsp:Policy>
                </sp:SignedSupportingTokens>
                <sp:Wss11 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
                    <wsp:Policy/>
                </sp:Wss11>
                <sp:Trust10 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
                    <wsp:Policy>
                        <sp:MustSupportIssuedTokens/>
                        <sp:RequireClientEntropy/>
                        <sp:RequireServerEntropy/>
                    </wsp:Policy>
                </sp:Trust10>
            </wsp:All>
        </wsp:ExactlyOne>
    </wsp:Policy>

我正确传递用户名和密码,如下所示

  <?xml version="1.0" encoding="utf-8"?><wsdl:definitions name="StandardApi" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:tns="http://tempuri.org/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:i0="http://cdx.dealerbuilt.com/Api/0.97/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsp1="http://www.w3.org/ns/ws-policy" xmlns:sc="http://schemas.sun.com/2006/03/wss/client" xmlns:wspp="http://java.sun.com/xml/ns/wsit/policy"><wsdl:import namespace="http://cdx.dealerbuilt.com/Api/0.97/" location="Api.svc.wsdl_wsdl0.xml"/><wsdl:types/><wsdl:binding name="CustomBinding_IStandardApi" type="i0:IStandardApi"><wsp1:PolicyReference URI="#CustomBinding_IStandardApiPolicy"/>
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/><wsdl:operation name="PullRepairOrders"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PullRepairOrders" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="PullRepairOrderByNumber"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PullRepairOrderByNumber" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="PushRepairOrders"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PushRepairOrders" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="PullAppointments"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PullAppointments" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="PushAppointments"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PushAppointments" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="CancelAppointments"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/CancelAppointments" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="UncancelAppointments"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/UncancelAppointments" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="PullCustomers"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PullCustomers" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="PullCustomerByKey"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PullCustomerByKey" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="CloseRepairOrderPayType"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/CloseRepairOrderPayType" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="PushRepairOrdersFromAppointments"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PushRepairOrdersFromAppointments" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="PushRepairOrderJobs"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PushRepairOrderJobs" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="PushRepairOrderLaborItems"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PushRepairOrderLaborItems" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="PushRepairOrderLaborOperationSublets"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PushRepairOrderLaborOperationSublets" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="PushRepairOrderParts"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PushRepairOrderParts" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="PullDealsByDealNumber"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PullDealsByDealNumber" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="GetTechnicians"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/GetTechnicians" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="PushAppraisals"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PushAppraisals" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="PullInventory"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PullInventory" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="PullInventoryByVin"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PullInventoryByVin" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="PullInventoryByStockNumber"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PullInventoryByStockNumber" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="PushInventory"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PushInventory" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="PushCustomers"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PushCustomers" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="PushCustomerVehicles"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PushCustomerVehicles" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="PullCustomerVehicles"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PullCustomerVehicles" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="PullCustomerVehiclesByCustomerKey"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PullCustomerVehiclesByCustomerKey" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="PushDeals"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PushDeals" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="PullDeals"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PullDeals" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="GetLenders"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/GetLenders" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="PushJournalEntries"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PushJournalEntries" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="PullJournalEntries"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PullJournalEntries" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="PullInventoryByVehicleKey"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PullInventoryByVehicleKey" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="PullProspects"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PullProspects" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="PullProspectByDealNumber"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PullProspectByDealNumber" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="PushProspects"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PushProspects" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="GetServiceAdvisors"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/GetServiceAdvisors" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="GetRepairOrderJobCodes"><soap:operation soapAction="http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/GetRepairOrderJobCodes" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation></wsdl:binding><wsdl:service name="StandardApi"><wsdl:port name="CustomBinding_IStandardApi" binding="tns:CustomBinding_IStandardApi"><soap:address location="https://cdx.dealerbuilt.com/0.97/Api.svc"/></wsdl:port></wsdl:service>
        <wsp1:Policy wsu:Id="CustomBinding_IStandardApiPolicy">
            <wsp1:ExactlyOne>
                <wsp1:All>
                    <sc:CallbackHandlerConfiguration wspp:visibility="private">
                        <sc:CallbackHandler default="test" name="usernameHandler"/>
                        <sc:CallbackHandler default="test123" name="passwordHandler"/>
                    </sc:CallbackHandlerConfiguration>
                </wsp1:All>
            </wsp1:ExactlyOne>
        </wsp1:Policy>
    </wsdl:definitions>

我做了很多搜索,但无法找到解决方案..

这段代码在.Net

中运行良好
        StandardApiClient api = new StandardApiClient();

        api.ClientCredentials.UserName.UserName = "test";

        api.ClientCredentials.UserName.Password = "test@123";

        Customer[] result = api.PullCustomers(125);

请告知。

0 个答案:

没有答案