简体   繁体   English

从WSDL生成客户端存根

[英]Generating client stubs from WSDL

I am starting on a new project with commercial vendor. 我正在与商业供应商开始一个新项目。 I need to write an integration module in our application to consume commercial vendor's web service. 我需要在我们的应用程序中编写一个集成模块来使用商业供应商的Web服务。 So, WSDL is not controlled by us. 因此,WSDL不受我们控制。

I think the general approach is to do a "Contract First" development and generate stubs from the WSDL file. 我认为一般方法是进行“契约优先”开发并从WSDL文件生成存根。 I would like to know what technologies are available to do this? 我想知道有哪些技术可以做到这一点? I would really like the simplest approach that works. 我真的很喜欢最简单的方法。 We use Maven 3.0.3 and Spring 3.0.5 extensively. 我们广泛使用Maven 3.0.3和Spring 3.0.5。 Can I use Spring WebServiceTemplate? 我可以使用Spring WebServiceTemplate吗?

Please let me know if the question isn't clear or additional details are needed. 如果问题不明确或需要其他详细信息,请与我们联系。

Thanks, Tapasvi 谢谢,Tapasvi

You can generate the java stubs with the maven plugin for JAX-WS . 您可以使用JAX-WSmaven插件生成Java存根。 Then you can use the stubs in spring to expose them as a webservice. 然后,您可以使用spring中的存根将它们作为Web服务公开。 Luckily, it's quite simple :). 幸运的是,这很简单:)。

Just a suggestion, don't re-generate the stubs every time you build the project, as (obviously) you won't be able to add any code to the stubs, which is sometimes very useful. 只是一个建议,不要在每次构建项目时重新生成存根,因为(显然)您将无法向存根添加任何代码,这有时非常有用。 I made this mistake long time ago and it was quite painful, because I had to put code in places where it didn't belong. 我很久以前犯了这个错误,这很痛苦,因为我不得不把代码放在它不属于的地方。 In the last few years I used a maven profile to generate the stubs on demand and then I merged them "manually" to add the extra code. 在过去的几年里,我使用maven配置文件按需生成存根,然后我“手动”合并它们以添加额外的代码。 Of course, this is only viable if the WSDL doesn't change very often. 当然,只有当WSDL不经常更改时,这才是可行的。

I have used axis and the easiest way to do is to run the utility wsdl2java and pass the location of the webservice along with the ?wdsl option. 我使用过轴,最简单的方法是运行实用程序wsdl2java并传递webservice的位置以及?wdsl选项。

I know lots of IDE's these days will allow to generate you stubs from within. 我知道很多IDE现在都可以从内部生成存根。 MyeclipseIDE has an option to ingest an WSDL so does intelliJ. MyeclipseIDE有一个选择来摄取WSDL,所以IntelliJ。 I think the safer approach is to use wsdl. 我认为更安全的方法是使用wsdl。 Also if you are using jax-ws you can try 此外,如果您使用jax-ws,您可以尝试

wsimport -keep -verbose location to wsdl wsimport -keep -verbose位置到wsdl

JAX-WS is included in the standard Java 6 distribution making it very simple to use. JAX-WS包含在标准Java 6发行版中,使其使用起来非常简单。

Generate stubs with wsimport in the JDK (remember to enable as many warnings as possible, as you want to know anything that may cause problems). 在JDK中使用wsimport生成存根(记住要尽可能多地启用警告,因为您想知道任何可能导致问题的事情)。

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

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