简体   繁体   English

从JavaScript调用Web服务的特定方法

[英]Call a specific method of a web service from JavaScript

I am new to web services, and I need to call a specific method from my web service. 我是Web服务的新手,我需要从Web服务中调用特定方法。 I had created a web service using NetBeans IDE, and now I need to call that using JavaScript. 我已经使用NetBeans IDE创建了一个Web服务,现在我需要使用JavaScript来调用它。

function validateForm(frm)
{
document.forms[0].action="http://localhost:8084/Web_Service_Example/CircleFunctions?wsdl"
document.forms[0].method="get"
document.forms[0].submit()
}

It is running properly on my local system. 它在我的本地系统上正常运行。
Now I need to call the method of my web service 现在,我需要调用我的Web服务的方法

public class CircleFunctions {
public int sum()
{
int a = 20;
int b = 40;
int c = a+b;
return c;
}
}

How can I call the sum() method of my CircleFunctions Class. 如何调用CircleFunctions类的sum()方法。 And is it possible to send the parameter to the method? 是否可以将参数发送给方法?

It looks like you are trying to call SOAP from JavaScript. 看来您正在尝试从JavaScript调用SOAP。 I do not normally recommend this. 我通常不建议这样做。 A REST architecture is much more in line with the JavaScript way of doing things. REST体系结构更符合JavaScript的处理方式。 However, let me refer you to the following SO question . 但是,让我向您介绍以下SO问题

My suggestion is for you to use REST for Java -> JavaScript and SOAP for Java -> Java. 我的建议是让您使用REST for Java-> JavaScript和SOAP for Java-> Java。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM