Web service, dynamic address in WSDL address

I am very new to web services, so sorry if I write a lot of the wrong things ...

I created several java classes and created wsdl, so I have a bottom-up web service. I expanded everything (in EAR) and called

http://localhost:7159/chc2/services/WebServiceManager 

to call the web service. It works, I get the results.

The problem is that I need to deploy the application on other servers and obviously the first part of the URL, the local ip will not be the same.

This url is declared by me in WSDL with:

 <wsdlsoap:address location="http://localhost:7159/chc2/services/WebServiceManager"/> 

My question is: is there a way to get the ip part of the link in a dynamic way in .wsdl? I found some ways on the net to do this in Java, but I directly call .wsdl and not through java ... I think if there is a way to do this in .wsdl.

Other configuration files that I have are server-config.wsdd and web.xml.

Thanks:)

+4
source share
4 answers

Some application servers allow you to send web services containing a WSDL with a dummy address:

 <soap:address location="REPLACE_WITH_ACTUAL_URL"/> 

After deployment, they will replace this value with the actual URL! Glassfish definitely supports this feature (in fact, I think you can put whatever you want into the address location value, Glassfish will replace it automatically), and according to this link , JBoss also supports this feature. ' NTN.

+3
source

As far as I understand, your problem is: when you deploy a web service on other servers, what would you call a web service?

Your servers are obviously part of the nodes / cluster. On a Java EE application server, such as WebSphere, plugin-config.xml you can configure incoming / outgoing HTTP ports.

The IBM HTTP web server will be configured on the application server through plugin-config.xml . This will open your web page as http: //: port / webserviceURI. This is the URL that you will use to call the web service regardless of the IP address of the application server.

+1
source

Dynamically generate wsdl via XSD using sws tagging in [servler-name] -servlet.xml

 <sws:dynamic-wsdl id="getemployeeDetails" portTypeName="EmpService" locationUri="/empService" targetNamespace="http://www.example.org/"> <sws:xsd location="/WEB-INF/employee.xsd"/> </sws:dynamic-wsdl> 

This way you might have a dynamic URL when hosted on a server

Hello

Anshol

+1
source

this way we can dynamically change the wsdl location url

 import java.io.File; import java.io.IOException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.xml.sax.SAXException; public class WsdlDynamicPath { public static void main(String[] args) { // TODO Auto-generated method stub try { changePath(); } catch (ParserConfigurationException | SAXException | IOException | TransformerException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void changePath() throws ParserConfigurationException, SAXException, IOException, TransformerException{ String filepath = "path to wsdl\\demo.wsdl"; //Give your wsdl file path DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document doc = docBuilder.parse(filepath); Node address= doc.getElementsByTagName("soap:address").item(0); NamedNodeMap attr = address.getAttributes(); Node nodeAttr = attr.getNamedItem("location"); nodeAttr.setTextContent("new path to wsdl"); // write the content into xml file TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(new File(filepath)); transformer.transform(source, result); } } 
0
source

All Articles