简体   繁体   English

如何生成使用WSDL动态位置的SOAP客户端代码?

[英]How to generate SOAP client code that uses dynamic location for WSDL?

I am using wsimport to generate client code for several WSDLs that are served by my application. 我正在使用wsimport为我的应用程序提供的几个WSDL生成客户端代码。 I have to run the app in several different places. 我必须在几个不同的地方运行该应用程序。 I am trying to simplify my client code generation/management problem. 我正在尝试简化我的客户端代码生成/管理问题。

What I have sort of slid back into is this. 我有点滑回来的是这个。 I have 3 interfaces and the app is installed in 3 places. 我有3个接口,应用程序安装在3个地方。 At this point, I have to generate 9 source bundles. 此时,我必须生成9个源包。 I also have 3 source directories, having driver code for each interface. 我还有3个源目录,每个接口都有驱动程序代码。

So, I have: 所以我有:

 src/srvr1.intf1/
 src/srvr1.intf2/
 src/srvr1.intf3/
 src/srvr2.intf1/
 src/srvr2.intf2/
 src/srvr2.intf3/
 src/srvr3.intf1/
 src/srvr3.intf2/
 src/srvr3.intf2/
 src/all.intf1
 src/all.intf2
 src/all.intf3

You can see how bad this is going to get when I have to move it up to over a dozen sites. 你可以看到当我必须将它移动到十几个站点时会有多糟糕。

One thing that has occurred to me is that I can go into the generated code and replace the hard-coded WSDL locations with System.getProperty("currentWSDL") and I can set this at run-time. 我遇到的一件事是我可以进入生成的代码并用System.getProperty(“currentWSDL”)替换硬编码的WSDL位置,我可以在运行时设置它。 SO, I got from 12 to 6. 所以,我从12点到6点。

I can use introspection in the "all" code to make it so that that is one class. 我可以在“所有”代码中使用内省来使它成为一个类。 This gets me to 4. And adding a server does not increase that number. 这让我得到4.并且添加服务器不会增加这个数字。

So, as far as I can see, if I go in and change the WSDL references to a property look-up, then I have to re-do that every single time I run wsimport. 所以,据我所知,如果我进入并将WSDL引用更改为属性查找,那么每次运行wsimport时我都必须重新执行该操作。 Does this make sense? 这有意义吗?

Is there some way to get wsimport to use a property-read instead of a hard-coded string for the WSDL? 有没有办法让wsimport使用属性读取而不是WSDL的硬编码字符串? I can even give it a value of the WSDL when I run wsimport. 我运行wsimport时甚至可以给它一个WSDL的值。 I just do not want to have to maintain n copies of the all 30+ client classes for n servers that are running the exact same app. 我只是不想为运行完全相同的应用程序的n个服务器维护所有30多个客户端类的n个副本。

You can set your service url like this. 您可以像这样设置服务网址。 there is no need for generating wsdl client for different server deployment unless it is changed. 除非更改,否则不需要为不同的服务器部署生成wsdl客户端。 You generate proxy and then in every client read url from any resource ( local file , database ...) and set url like this 您生成代理,然后在每个客户端从任何资源(本地文件,数据库...)读取URL并设置这样的URL

String url = //read url from config file or any other resoure like db ((BindingProvider)proxy).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url); String url = //从配置文件或任何其他资源中读取url,如db((BindingProvider)代理).getRequestContext()。put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,url);

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

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