Java调用.net的web service

Java调用.netwebservice,我的java ideNetBeans,要调用

 

新建一个java页面写下如下代码!

try {

            Integer i = new Integer(1);

            Integer j = new Integer(2);

            String endpoint="http://localhost:49573/WebService1.asmx";

            Service service = new Service();

            Call call = (Call)service.createCall();

            call.setTargetEndpointAddress(new java.net.URL(endpoint));

            call.setOperationName(new QName("http://localhost:49573/WebService1.asmx","IntAdd"));

            call.addParameter("a",org.apache.axis.encoding.XMLType.XSD_INT,javax.xml.rpc.ParameterMode.IN);

            call.addParameter("b",org.apache.axis.encoding.XMLType.XSD_INT,javax.xml.rpc.ParameterMode.IN);

            call.setReturnType(org.apache.axis.encoding.XMLType.XSD_INT);

            Integer k = (Integer)call.invoke(new Object[]{i,j});

            JOptionPane.showMessageDialog(null,k.toString());

 

            }

            catch (Exception e) {System.err.println(e.toString());}  

 

 

然后建立一个.netwebservice项目,添加如下代码

 

    /// <summary>

    /// WebService1 的摘要说明

    /// </summary>

    ///

 

    [WebService(Namespace = "http://localhost:49573/WebService1.asmx")]

    [SoapDocumentService(RoutingStyle = SoapServiceRoutingStyle.RequestElement)]

    [ToolboxItem(false)]

    public class WebService1 : System.Web.Services.WebService

    {

 

        [WebMethod]

        public string HelloWorld()

        {

            return "Hello World";

        }

 

        [WebMethod]

        public int IntAdd(int a, int b)

        {

            return a + b;

        }

}

 

现在调用可以开始了.可是我发现参数ab的值传不到.net webservice.不知道为什么.传过去.ab都是0 !
请教各位!

posted @ 2008-07-24 15:44  索马  阅读(751)  评论(1编辑  收藏  举报