java程序如何生成客户端_java – 一个wsimport生成的客户端如何工作?

在回答这些问题之前,有一些澄清:JAX-WS是一个在Java中实现Web服务的规范。它描述了WSDL工件如何映射到Java类以及如何使用注释应用此映射。您可以使用

download the specification here.工具wsimport是本规范的参考实现的一部分,参考实现是Java类库的一部分。有几个替代实现,例如Axis2,CXF或Metro,它们通过支持WS-ReliableMessaging或WS-Security等附加标准来增强基本的JAX-WS支持。

现在你的问题:

Am I correct with my assumptions above?

是的,你是。

What are the function of the other classes?

软件包信息用于将Web服务中使用的XML命名空间映射到实现类所在的包。命名空间通常看起来与Java包名称不同(通常它是一个URL),这使映射成为必要。

ObjectFactory允许您创建服务发送和接收的任何消息。如果你想挂在你的stub类前面的代码,提供修改的消息或类似的东西,你需要这个。

我看不到你的类的内容,但是如果我明白了,MyWebServicePortType是一个类似于WSDL中的portType的接口。也就是说,它将操作及其在WSDL中的签名映射到Java方法。如果您要提供服务(您不需要提供客户端),则需要实现此接口。在您实现客户端时,您只需使用它。

最后,如果要调用Web服务,MyWebService类包含您需要的客户端存根。

I inspected MyWebService and it contains an annotation referring to

the absolute location of the WSDL I used to generate the client. What

is the relevance of specifying the wsdllocation in the client? How

does the client use that info?

您生成的界面包含服务的portType的签名,但不能解释您如何与服务对话。这是WSDL中绑定的一部分。最基本的设置是使用SOAP over HTTP的消息的文档/文字样式。其他配置,例如SOAP over JMS,是可能的,您的客户端需要知道要使用的协议。因此它需要绑定WSDL。另外,正如您稍后所述,您的Java文件中没有端点地址。该地址也是从WSDL中读取的。

I noticed that the actual URL of the web service is not declared in

any of the classes generated. How does the client know where it needs

to connect to?

它从WSDL中的服务端口读取地址。它位于WSDL的末尾。

Was the WSDL file annotated so that the client can read the URL on the

WSDL file upon connection?

不,端口是具体Web服务端点的典型元素。这里没有什么特别的要求

If so, then does it mean that the WSDL file is always read when a new

connection must be established?

那么客户端可能有缓存(我不知道这个参考实现的细节)。从概念的角度来看:是的,是的。

What if I need to connect to an HTTPS. How can I set the server

certificate

这可能很棘手,我不能给你一个开箱即用的答案。我建议阅读有关这个​​话题的问题such as this one。

Is there any difference when I generate my client using wsimport and

when I generate it using Axis2 or Apache CXF

就在这里。 wsimport更好,不要使用wsdl2java。 Here is a description, why。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值