Web 服务跨语言参数类型
我正在创建一个网络服务。我想知道如何声明参数类型并使用它 因为 Java 类型不同,例如。日期。我已经编写了客户端来使用 Java 中的 Web 服务,运行良好,但我想知道我是否可以使用用其他语言编写的客户端来使用相同的 Web 服务。我给你一个我的网络服务的代码示例:
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
import javax.xml.ws.Endpoint;
@WebService
public class WiseQuoteServer {
@SOAPBinding(style = Style.RPC)
public String getQuote(String category) {
if (category.equals("fun")) {
return "5 is a sufficient approximation of infinity.";
}
if (category.equals("work")) {
return "Remember to enjoy life, even during difficult situatons.";
} else {
return "Becoming a master is relatively easily. Do something well and then continue to do it for the next 20 years";
}
}
public static void main(String[] args) {
WiseQuoteServer server = new WiseQuoteServer();
Endpoint endpoint = Endpoint.publish(
"http://localhost:9191/wisequotes", server);
}
}
I am creating a web service. I want to know how do I declare parameter type and use it
as Java type is different for eg. date. I have written client to consume web services in Java which is working fine, but I want to know whether I can consume same web services using client written in some other language. I am giving you a code example of my web service:
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
import javax.xml.ws.Endpoint;
@WebService
public class WiseQuoteServer {
@SOAPBinding(style = Style.RPC)
public String getQuote(String category) {
if (category.equals("fun")) {
return "5 is a sufficient approximation of infinity.";
}
if (category.equals("work")) {
return "Remember to enjoy life, even during difficult situatons.";
} else {
return "Becoming a master is relatively easily. Do something well and then continue to do it for the next 20 years";
}
}
public static void main(String[] args) {
WiseQuoteServer server = new WiseQuoteServer();
Endpoint endpoint = Endpoint.publish(
"http://localhost:9191/wisequotes", server);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
吉格尔是正确的。 JAX-WS 使用 JAXB 将参数转换为 XML。 JAXB 具有一组广泛的注释,您可以使用它们来自定义将数据转换为 XML 的方式。由于数据以 XML 形式发送,几乎任何语言都可以读取/写入该服务。此外,大多数语言都有某种可用的 SOAP 库。
Jigar is correct. JAX-WS uses JAXB to convert parameters into XML. JAXB has an extensive set of annotations that you can use to customize how the data is turned into XML. Since the data is sent as XML almost any language can read/write to the service. Furthermore, most languages have some kind of SOAP library available.