2011-07-12 78 views
1

我想创建一个Java Web服务客户端与IntelliJ IDEA,但我得到的错误。我的网络服务“MagicEightBall”是一种简约服务,它有一个方法:“GetAdvice”,它不接受任何参数并返回一个字符串。当我使用的IntelliJ创建一个Web服务客户端(使用GlashFish/JAXWS 2.X RI /地铁1.X/2.0 JWSDP),我得到了下面的代码:IntelliJ网络客户端错误

public class HelloWorldClient { 
    public static void main(String[] argv) { 
     pakeightball.IMagicEightBallService service = new MagicEightBallService().(); 
     //invoke business method 
     service.getAdvice(); 
    } 
} 

我想这与WCF basicHttpBinding的服务,修复了一些代码,并且它工作正常。我现在试图连接到WCF的wsHttpBinding(使用SSL)服务,但出现错误。首先,这里固定了代码(我不得不禁用证书验证):

import javax.net.ssl.*; 
import pakeightball.*; 

public class HelloWorldClient { 

    public static void DisableCertificateValidation() { 
      TrustManager[] trustAllCerts = new TrustManager[]{ 
       new X509TrustManager() { 
        public X509Certificate[] getAcceptedIssuers() { return null; } 
        public void checkClientTrusted(X509Certificate[] certs, String authType) { } 
        public void checkServerTrusted(X509Certificate[] certs, String authType) { } 
       } 
      }; 
      try { 
       SSLContext sc = SSLContext.getInstance("SSL"); 
       sc.init(null, trustAllCerts, new java.security.SecureRandom()); 
       HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); 
      } catch (Exception e) { 
      } 
    } 

    public static void main(String[] argv) { 
     MagicEightBallService locator = new MagicEightBallService(); 
     IMagicEightBallService service = locator.getWSHttpBindingTransportSecurityIMagicEightBallService(); 

     // disable certificate validation 
     DisableCertificateValidation(); 

     //invoke business method 
     String result = service.getAdvice(); 
     System.out.println(result); 
    } 

} 

该代码编译,但给出了以下运行时错误:

"C:\Program Files\Java\jdk1.6.0_26\bin\java" -Didea.launcher.port=7532 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 10.5.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.6.0_26\jre\lib\alt-rt.jar;C:\Program Files\Java\jdk1.6.0_26\jre\lib\alt-string.jar;C:\Program Files\Java\jdk1.6.0_26\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.6.0_26\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.6.0_26\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.6.0_26\jre\lib\jce.jar;C:\Program Files\Java\jdk1.6.0_26\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.6.0_26\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.6.0_26\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.6.0_26\jre\lib\resources.jar;C:\Program Files\Java\jdk1.6.0_26\jre\lib\rt.jar;C:\Program Files\Java\jdk1.6.0_26\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.6.0_26\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.6.0_26\jre\lib\ext\sunjce_provider.jar;C:\Users\Jay.MVP\IdeaProjects\TryMagicEightBallClient3\out\production\TryMagicEightBallClient3;C:\Users\Jay.MVP\IdeaProjects\TryMagicEightBallClient3\lib\activation.jar;C:\Users\Jay.MVP\IdeaProjects\TryMagicEightBallClient3\lib\FastInfoset.jar;C:\Users\Jay.MVP\IdeaProjects\TryMagicEightBallClient3\lib\http.jar;C:\Users\Jay.MVP\IdeaProjects\TryMagicEightBallClient3\lib\jaxb-api.jar;C:\Users\Jay.MVP\IdeaProjects\TryMagicEightBallClient3\lib\jaxb-impl.jar;C:\Users\Jay.MVP\IdeaProjects\TryMagicEightBallClient3\lib\jaxb-xjc.jar;C:\Users\Jay.MVP\IdeaProjects\TryMagicEightBallClient3\lib\jaxws-api.jar;C:\Users\Jay.MVP\IdeaProjects\TryMagicEightBallClient3\lib\jaxws-rt.jar;C:\Users\Jay.MVP\IdeaProjects\TryMagicEightBallClient3\lib\jaxws-tools.jar;C:\Users\Jay.MVP\IdeaProjects\TryMagicEightBallClient3\lib\jsr173_api.jar;C:\Users\Jay.MVP\IdeaProjects\TryMagicEightBallClient3\lib\jsr181-api.jar;C:\Users\Jay.MVP\IdeaProjects\TryMagicEightBallClient3\lib\jsr250-api.jar;C:\Users\Jay.MVP\IdeaProjects\TryMagicEightBallClient3\lib\resolver.jar;C:\Users\Jay.MVP\IdeaProjects\TryMagicEightBallClient3\lib\saaj-api.jar;C:\Users\Jay.MVP\IdeaProjects\TryMagicEightBallClient3\lib\saaj-impl.jar;C:\Users\Jay.MVP\IdeaProjects\TryMagicEightBallClient3\lib\sjsxp.jar;C:\Users\Jay.MVP\IdeaProjects\TryMagicEightBallClient3\lib\stax-ex.jar;C:\Users\Jay.MVP\IdeaProjects\TryMagicEightBallClient3\lib\streambuffer.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 10.5.1\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain example.HelloWorldClient 
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: MustUnderstand headers:[{http://www.w3.org/2005/08/addressing}Action] are not understood 
    at com.sun.xml.ws.protocol.soap.MUTube.createMUSOAPFaultException(MUTube.java:140) 
    at com.sun.xml.ws.protocol.soap.ClientMUTube.processResponse(ClientMUTube.java:82) 
    at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:569) 
    at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:518) 
    at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:503) 
    at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:400) 
    at com.sun.xml.ws.client.Stub.process(Stub.java:228) 
    at com.sun.xml.ws.client.sei.SEIStub.doProcess(SEIStub.java:120) 
    at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:226) 
    at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:206) 
    at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:103) 
    at $Proxy30.getAdvice(Unknown Source) 
    at example.HelloWorldClient.main(HelloWorldClient.java:36) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120) 

Process finished with exit code 1 

是的IntelliJ IDEA的WebService的客户端能够使用basicHttpBinding以外的WCF服务?我在这里做错了什么?任何指导将不胜感激。

谢谢!

编辑:

下面是WCF服务的Web.config:

<?xml version="1.0"?> 
<configuration> 

    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    </system.web> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 

    <system.serviceModel> 
    <services> 
     <service name="Petio.MagicEightBall.MagicEightBallService" behaviorConfiguration="MagicEightBallServiceBehavior"> 

     <endpoint name="WSHttpBinding_TransportSecurity_IMagicEightBallService" 
        address="https://localhost/MagicEightBall/MagicEightBallService.svc" 
        binding="wsHttpBinding" 
        bindingConfiguration="TransportSecurity" 
        contract="Petio.MagicEightBall.IMagicEightBallService" /> 
     <endpoint address="mex" 
        binding="mexHttpsBinding" 
        contract="IMetadataExchange" /> 
     </service> 
    </services> 

    <behaviors> 
     <serviceBehaviors> 
     <behavior name="MagicEightBallServiceBehavior"> 
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/> 
      <serviceDebug includeExceptionDetailInFaults="true"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 

    <bindings> 
     <wsHttpBinding> 
     <binding name="TransportSecurity"> 
      <security mode="Transport"> 
      <transport clientCredentialType="None"/> 
      </security> 
     </binding> 
     </wsHttpBinding> 

    </bindings> 


    </system.serviceModel> 
</configuration> 

这里是一个的生成WSDL:

<wsdl:definitions 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:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" name="MagicEightBallService" targetNamespace="http://tempuri.org/"> 
    <wsp:Policy wsu:Id="WSHttpBinding_TransportSecurity_IMagicEightBallService_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> 
      </wsp:Policy> 
     </sp:TransportBinding> 
     <wsaw:UsingAddressing/> 
     </wsp:All> 
    </wsp:ExactlyOne> 
    </wsp:Policy> 
    <wsdl:types> 
    <xsd:schema targetNamespace="http://tempuri.org/Imports"> 
     <xsd:import schemaLocation="http://my.local.domain.name/MagicEightBall/MagicEightBallService.svc?xsd=xsd0" namespace="http://tempuri.org/"/> 
     <xsd:import schemaLocation="http://my.local.domain.name/MagicEightBall/MagicEightBallService.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/> 
    </xsd:schema> 
    </wsdl:types> 
    <wsdl:message name="IMagicEightBallService_GetAdvice_InputMessage"> 
    <wsdl:part name="parameters" element="tns:GetAdvice"/> 
    </wsdl:message> 
    <wsdl:message name="IMagicEightBallService_GetAdvice_OutputMessage"> 
    <wsdl:part name="parameters" element="tns:GetAdviceResponse"/> 
    </wsdl:message> 
    <wsdl:portType name="IMagicEightBallService"> 
    <wsdl:operation name="GetAdvice"> 
     <wsdl:input wsaw:Action="http://tempuri.org/IMagicEightBallService/GetAdvice" message="tns:IMagicEightBallService_GetAdvice_InputMessage"/> 
     <wsdl:output wsaw:Action="http://tempuri.org/IMagicEightBallService/GetAdviceResponse" message="tns:IMagicEightBallService_GetAdvice_OutputMessage"/> 
    </wsdl:operation> 
    </wsdl:portType> 
    <wsdl:binding name="WSHttpBinding_TransportSecurity_IMagicEightBallService" type="tns:IMagicEightBallService"> 
    <wsp:PolicyReference URI="#WSHttpBinding_TransportSecurity_IMagicEightBallService_policy"/> 
    <soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/> 
    <wsdl:operation name="GetAdvice"> 
     <soap12:operation soapAction="http://tempuri.org/IMagicEightBallService/GetAdvice" style="document"/> 
     <wsdl:input> 
     <soap12:body use="literal"/> 
     </wsdl:input> 
     <wsdl:output> 
     <soap12:body use="literal"/> 
     </wsdl:output> 
    </wsdl:operation> 
    </wsdl:binding> 
    <wsdl:service name="MagicEightBallService"> 
    <wsdl:port name="WSHttpBinding_TransportSecurity_IMagicEightBallService" binding="tns:WSHttpBinding_TransportSecurity_IMagicEightBallService"> 
     <soap12:address location="https://localhost/MagicEightBall/MagicEightBallService.svc"/> 
     <wsa10:EndpointReference> 
     <wsa10:Address> 
      https://localhost/MagicEightBall/MagicEightBallService.svc 
     </wsa10:Address> 
     </wsa10:EndpointReference> 
    </wsdl:port> 
    </wsdl:service> 
</wsdl:definitions> 
+0

'WsHttpBinding'使用'WS-Addressing 1.0',因此请确保它被正确处理。错误表示寻址存在一些问题。 –

+0

我刚刚使用命令行环境和Axis2尝试了同样的事情,并且遇到了同样的问题:ERROR org.apache.axis2.engine.AxisEngine - 必须明白标头检查失败http://www.w3.org/ 2005/08 /致:行动 –

回答

0

我会更改以下行...

IMagicEightBallService service = locator.getWSHttpBindingTransportSecurityIMagicEightBallService(); 

为...

IMagicEightBallService service = locator.getWSHttpBindingTransportSecurityIMagicEightBallService(new javax.xml.ws.soap.AddressingFeature()); 

它为我工作。