分享

转:用Java调用WebService接口 - jinesin随笔 - jinesin - 和讯博客

 ShangShujie 2010-07-24

这是一个用Java调用C#版WebService接口的例子:

C#接口:

0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top"> using  System;
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top">
using  System.Web;
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top">
using  System.Web.Services;
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top">
using  System.Web.Services.Protocols;
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top">
using  System.Web.Services.Description;
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top">
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top">
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top"> [WebService(Namespace 
=   " http://www./ " )]
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top"> [WebServiceBinding(ConformsTo 
=  WsiProfiles.BasicProfile1_1)]
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top">
public   class  Service : System.Web.Services.WebService
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" id="_303_939_Open_Image" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align="top"> 0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" id="_303_939_Closed_Image" style="display: none;" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" align="top">
{
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" id="_327_398_Open_Image" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"> 0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" id="_327_398_Closed_Image" style="display: none;" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" align="top">     
public  Service ()  {
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">         
// 如果使用设计的组件,请取消注释以下行 
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">         
// InitializeComponent(); 
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top">
    }

0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">     [SoapRpcMethod(Action 
=   " http://www./Add " , RequestNamespace  =   " http://www./T " , ResponseNamespace  =   " http://www./T " , Use  =  SoapBindingUse.Literal)]
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">     [WebMethod]
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">     
public   int  Add( int  a,  int  b)
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" id="_632_660_Open_Image" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"> 0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" id="_632_660_Closed_Image" style="display: none;" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" align="top">     
{
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">         
return  a  +  b;
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top">     }

0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">     [SoapRpcMethod(Action 
=   " http://www./Hello " , RequestNamespace  =   " http://www./T " , ResponseNamespace  =   " http://www./T " , Use  =  SoapBindingUse.Literal)]
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">     [WebMethod]
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">     
public  String HelloWorld()
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" id="_894_932_Open_Image" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"> 0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" id="_894_932_Closed_Image" style="display: none;" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" align="top">     
{
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">         
return   " Hello, world! " ;
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top">     }

0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">     
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align="top"> }

0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top">


Java调用这个Webservice中的Add方法和HelloWorld方法:

1.有参方法:Add

0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" id="_29_1019_Open_Image" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align="top"> public   static   void  addTest()  {
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" id="_37_964_Open_Image" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"> 0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" id="_37_964_Closed_Image" style="display: none;" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" align="top">         
try   {
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             Integer i 
=   1 ;
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             Integer j 
=   2 ;
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             
// WebService URL
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">
            String service_url  =   " http://localhost:4079/ws/Service.asmx " ;
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             Service service 
=   new  Service();
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             Call call 
=  (Call) service.createCall();
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             call.setTargetEndpointAddress(
new  java.net.URL(service_url));
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             
// 设置要调用的方法
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">
            call.setOperationName( new  QName( " http://www./T " " Add " ));
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             
// 该方法需要的参数
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">
            call.addParameter( " a " , org.apache.axis.encoding.XMLType.XSD_INT,
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">                     javax.xml.rpc.ParameterMode.IN);
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             call.addParameter(
" b " , org.apache.axis.encoding.XMLType.XSD_INT,
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">                     javax.xml.rpc.ParameterMode.IN);
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             
// 方法的返回值类型
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">
            call.setReturnType(org.apache.axis.encoding.XMLType.XSD_INT);
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             call.setUseSOAPAction(
true );
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             call.setSOAPActionURI(
" http://www./Add " );
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             
// 调用该方法
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">
            Integer res  =  (Integer)call.invoke(
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" id="_875_893_Open_Image" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"> 0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" id="_875_893_Closed_Image" style="display: none;" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" align="top">                     
new  Object[] {
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">                         i, j
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top">                     }

0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             );
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             System.out.println( 
" Result:  "   +  res.toString());
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" id="_986_1016_Open_Image" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"> 0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" id="_986_1016_Closed_Image" style="display: none;" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" align="top">         }
  catch  (Exception e)  {
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             System.err.println(e);
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top">         }

0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align="top">     }
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" id="_29_1019_Closed_Image" style="display: none;" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" align="top">

运行,结果返回:Result:3

2.无参方法:HelloWorld

0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" id="_31_621_Open_Image" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align="top"> public   static   void  helloTest()  {
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" id="_39_555_Open_Image" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"> 0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" id="_39_555_Closed_Image" style="display: none;" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" align="top">         
try   {
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             String endpoint 
=   " http://localhost:4079/ws/Service.asmx " ;
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             Service service 
=   new  Service();
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             Call call 
=  (Call) service.createCall();
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             call.setTargetEndpointAddress(
new  java.net.URL(endpoint));
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             call.setOperationName(
new  QName( " http://www./T " " HelloWorld " ));
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             call.setUseSOAPAction(
true );
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             call.setSOAPActionURI(
" http://www./Hello " );
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             String res 
=  (String)call.invoke(
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" id="_477_495_Open_Image" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"> 0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" id="_477_495_Closed_Image" style="display: none;" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" align="top">                     
new  Object[] {
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">                         
null
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top">                     }

0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             );
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             System.out.println( 
" Result:  "   +  res);
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" id="_577_618_Open_Image" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"> 0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" id="_577_618_Closed_Image" style="display: none;" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" align="top">         }
  catch  (Exception e)  {
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top">             System.err.println(e.toString());
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top">         }

0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align="top">     }
0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" id="_31_621_Closed_Image" style="display: none;" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" src_cetemp="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" align="top">

可以看到,调用无参的webservice和有参的基本相同,不过无参调用时,不需要调用Call的addParameter方法和setReturnType方法
执行结果返回:Hello, world!

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多