當前位置:編程學習大全網 - 源碼下載 - 調用webservice 服務很不穩定 是咋回事

調用webservice 服務很不穩定 是咋回事

basic認證:我用的是XFIRE。 ,首先修改services.xmlHelloWorldcom.ktsfot.ws.security.IHelloWorldcom.ktsfot.ws.security.HelloWorldImplwrappedliteralapplication ,AuthenticationHandler類的寫法packagecom.ktsfot.ws.security;importorg.codehaus.xfire.MessageContext;importorg.codehaus.xfire.handler.AbstractHandler;importorg.jdom.*;publicclassAuthenticationHandlerextendsAbstractHandler{publicvoidinvoke(MessageContextcfx)throwsException{//TODOAuto-generatedmethodstubif(cfx.getInMessage().getHeader()==null)if(cfx.getInMessage().getHeader()==null){throwneworg.codehaus.xfire.fault.XFireFault("請求必須包含驗證信息",org.codehaus.xfire.fault.XFireFault.SENDER);}Elementtoken=cfx.getInMessage().getHeader().getChild("AuthenticationToken");if(token==null){throwneworg.codehaus.xfire.fault.XFireFault("請求必須包含身份驗證信息",org.codehaus.xfire.fault.XFireFault.SENDER);}Stringusername=token.getChild("Username").getValue();Stringpassword=token.getChild("Password").getValue();try{//進行身份驗證,只有abcd@ 的用戶為授權用戶if(username.equals("abcd")&&password.equals(" "))//這語句不顯示System.out.println("身份驗證通過");elsethrownewException();}catch(Exceptione){throwneworg.codehaus.xfire.fault.XFireFault("非法的用戶名和密碼",org.codehaus.xfire.fault.XFireFault.SENDER);}}} ,客戶端調用:HelloWorldClientclient=newHelloWorldClient();//createadefaultserviceendpointHelloWorldPortTypeservice=client.getHelloWorldHttpPort();XFireProxyproxy=(XFireProxy)Proxy.getInvocationHandler(service);proxy.getClient().addOutHandler(newClientAuthenticationHandler("abcd"," "));System.out.print(service.sayHello());System.exit( );

  • 上一篇:「原創」智慧物流重要元件——激光雷達展望
  • 下一篇:我的QQ號被盜
  • copyright 2024編程學習大全網