gpt4 book ai didi

java - Web 服务跨语言参数类型

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:01:47 25 4
gpt4 key购买 nike

我正在创建一个网络服务。我想知道如何声明参数类型并使用它因为 Java 类型是不同的,例如。日期。我已经编写了客户端来使用 Java 中的 Web 服务,它运行良好,但我想知道我是否可以使用以其他语言编写的客户端来使用相同的 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);
}
}

最佳答案

Jigar 是正确的。 JAX-WS 使用 JAXB 将参数转换为 XML。 JAXB 有一组广泛的注释,您可以使用它们来自定义将数据转换为 XML 的方式。由于数据以 XML 形式发送,几乎任何语言都可以读取/写入服务。此外,大多数语言都有某种可用的 SOAP 库。

关于java - Web 服务跨语言参数类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5758382/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com