java_soap

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

106JavaRPCJavaJavabeanSOAPSOAPJavaurn:BasicTradingServicegetTotalVolumeJava107packagejavasoap.book.ch5;publicclassBasicTradingService{publicBasicTradingService(){}publicintgetTotalVolume(String[]stocks){////inttotal=345000;returntotal;}}BasicTradingServicegetTotalVolume()stocksApacheSOAPurn:BasicTradingServiceisd:servicexmlns:isd==urn:BasicTradingServiceisd:providertype=javascope=Applicationmethods=getTotalVolumeisd:javaclass=javasoap.book.ch5.BasicTradingServicestatic=false//isd:providerisd:faultListenerorg.apache.soap.server.DOMFaultListener/isd:faultListenerisd:mappings/isd:mappings/isd:serviceApacheSOAPAdmin108packagejavasoap.book.ch5;importjava.net.*;importjava.util.*;importorg.apache.soap.*;importorg.apache.soap.rpc.*;publicclassVolumeClient{publicstaticvoidmain(String[]args)throwsException{URLurl=newURL();Callcall=newCall();call.setTargetObjectURI(urn:BasicTradingService);call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);String[]stocks={MINDSTRM,MSFT,SUN};Vectorparams=newVector();params.addElement(newParameter(stocks,String[].class,stocks,null));call.setParams(params);try{call.setMethodName(getTotalVolume);Responseresp=call.invoke(url,);Parameterret=resp.getReturnValue();Objectvalue=ret.getValue();System.out.println(TotalVolumeis+value);}catch(SOAPExceptione){System.err.println(CaughtSOAPException(+e.getFaultCode()+):+e.getMessage());}}}ParameterString[].classstocksTotalVolumeis345000109getTotalVolumeSOAPSOAP-ENV:Envelopexmlns:SOAP-ENV=:xsi=:xsd=:Bodyns1:getTotalVolumexmlns:ns1=urn:BasicTradingServiceSOAP-ENV:encodingStyle=:ns2=:type=ns2:Arrayns2:arrayType=xsd:string[3]itemxsi:type=xsd:stringMINDSTRM/itemitemxsi:type=xsd:stringMSFT/itemitemxsi:type=xsd:stringSUN/item/stocks/ns1:getTotalVolume/SOAP-ENV:Body/SOAP-ENV:Envelopestocksxsi:typens2:Arrayns2ns2:arrayTypexsd:string[3]3xsd:stringstocksitemSOAPxsi:typexsd:stringhomogeneousarrayheterogeneousarrayJavaCprintf()Java110urn:BasicTradingServiceexecuteTradetrue1BasicTradingServicepackagejavasoap.book.ch5;publicclassBasicTradingService{publicBasicTradingService(){}publicintgetTotalVolume(String[]stocks){////inttotal=345000;returntotal;}publicStringexecuteTrade(Object[]params){Stringresult;try{Stringstock=(String)params[0];IntegernumShares=(Integer)params[1];Booleanbuy=(Boolean)params[2];StringorderType=Buy;if(false==buy.booleanValue()){orderType=Sell;}result=(orderType++numShares+of+stock);}catch(ClassCastExceptione){result=BadParameterTypeEncountered;}returnresult;}}1Javabean111executeTrade()paramsObject[]StringIntegerBooleantry/catchSOAPexecuteTrade()resultexecuteTradeObject[]multiParamsObject[]MINDSTRM100trueJavaObjectJavaJavaParameterObject[].classpackagejavasoap.book.ch5;importjava.net.*;importjava.util.*;importorg.apache.soap.*;importorg.apache.soap.rpc.*;publicclassTradingClient{publicstaticvoidmain(String[]args)throwsException{URLurl=newURL();Callcall=newCall();call.setTargetObjectURI(urn:BasicTradingService);call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);Object[]multiParams={MINDSTRM,newInteger(100),newBoolean(true)};Vectorparams=newVector();params.addElement(newParameter(params,Object[].class,multiParams,null));call.setParams(params);112try{call.setMethodName(executeTrade);Responseresp=call.invoke(url,);Parameterret=resp.getReturnValue();Objectvalue=ret.getValue();System.out.println(TradeDescription:+value);}catch(SOAPExceptione){System.err.println(CaughtSOAPException(+e.getFaultCode()+):+e.getMessage());}}}executeTrade()TradeDescription:Buy100ofMINDSTRMmultiParamsexecuteTrade()SOAPSOAP-ENV:Envelopexmlns:SOAP-ENV=:xsi=:xsd=:Bodyns1:executeTradexmlns:ns1=urn:BasicTradingServiceSOAP-ENV:encodingStyle=:ns2=:type=ns2:Arrayns2:arrayType=xsd:anyType[3]itemxsi:type=xsd:stringMINDSTRM/itemitemxsi:type=xsd:int100/itemitemxsi:type=xsd:booleantrue/item/params/ns1:executeTrade/SOAP-ENV:Body/SOAP-ENV:Envelope113xsi:typens2:Arrayparamsns2:arrayTypexsd:anyType[3]32GLUEBasicTradingServiceGLUEJava:packagejavasoap.book.ch5;importelectric.util.Context;importelectric.registry.Registry;importelectric.server.http.HTTP;publicclassBasicTradingApp{publicstaticvoidmain(String[]args)throwsException{HTTP.startup();Contextcontext=newContext();context.addProperty(activation,application);context.addProperty(namespace,urn:BasicTradingService);Registry.publish(urn:BasicTradingService,javasoap.

1 / 36
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功