Java – use the WebService client generated by wsimport to change the URL

I am writing a module for a Java application that accesses web services described in WSDL The source WSDL is directly from what I think is ASP Net web service download; The service website is shown in The asmx extension ends, and viewing the service URL in the browser displays a link that can be used to download WSDL

One of my key requirements is the ability to switch service URLs without recompiling The URL given to me is obviously a test server. I know I will be given a production URL to use in production I also hope to create a simulation server for testing, and reserve the ability to specify a new URL in the future without recompiling the service and moving it In fact, I want to install our application so that multiple instances of web service can be instantiated at different URLs

But my idea doesn't seem to have anything to do with what the wsimport tool is doing for me Following f1sh's answer here, I use the following command to generate java code from the WSDL I downloaded:

wsimport -Xnocompile -keep -b binding.xml wsdlFile.wsdl

I found that the generated code is correct for the wsdlfile I downloaded The WSDL (containing the service URL) has a hard - coded reference Our application will not run as configured by editing the WSDL file at run time I need to compile the code into my application at build time and set the service URL at instantiation time

I'm not quite sure why WSDL even needs to be parsed at run time; My understanding is that WSDL provides enough information to generate code that can access WebService, so I don't know what it provides to the generated code instead of the service URL. I don't know why the service URL does not provide a constructor or is configured through the methods on the generated WebService class I must have missed something

What is the general practice in this case? Most people will regenerate the code for each URL they want to use? Generate code at run time? Can I use another WSDL tool that will build client code using configurable URLs?

Solution

Copy one from the source you generated QName is an XML qualified name - a "unique" identity

I can't say I know for sure, but WSDL is basically a schema By providing it, I guess you give Jax - ws a mechanism to validate soap responses I don't think JAXB binding is enough to do this

I always use the two parameter constructor in the generated service through classloader The getresource method provides a URL to embed the WSDL into my jar As with any mode, using remote or file system URLs is stupid and less optimized

See this question for how to set the end point at runtime

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>