这是一个用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
运行,结果返回:Result:3
2.无参方法:HelloWorld
可以看到,调用无参的webservice和有参的基本相同,不过无参调用时,不需要调用Call的addParameter方法和setReturnType方法 执行结果返回:Hello, world!
|