Search code examples
phpweb-servicessoapwsdl

Using a dynamic IP address for the service provider in a WSDL file


We're running a soap server using PHP, and currently the IP address is hard coded in the WSDL file for providing operations etc. However, there are plans to have the server on larger networks where it may not be able to dictate it's own IP address, and so it needs to allow a dynamic address.

Here's a couple of examples of places with this static IP address.

<wsdl:definitions name="itl_ukmachines" targetNamespace="http://10.10.8.89/InPrServerSys/sp/service.php" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://10.10.8.89/InPrServerSys/sp/service.php" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

and

<wsdl:operation name="MachineHostPowerUpRegistration">

    <soap:operation
    soapAction="http://10.10.8.89/InPrServerSys/sp/service.php/MachineHostPowerUpRegistration" />
    <wsdl:input>

        <soap:body use="literal" />
    </wsdl:input>
    <wsdl:output>

        <soap:body use="literal" />
    </wsdl:output>
</wsdl:operation>

Is there a way to have the php server replace these IP addresses up with it's current IP address on startup, or simply a special value that can go in there so this will work?


Solution

  • If you want the clients to be able to consume your service without any need of configuration on their side, you will have to dynamically generate the WSDL whenever it is being requested.

    Many platforms enable such behavior. For example take Axis: If you have a service at http://Url/MyService you'd also have the WSDL for the service accessible at http://Url/MyService?wsdl. The WSDL is generated each time.

    I don't know what tools you have at your disposal, but you can easily achieve the same behavior even with plain PHP. First, replace the IPs with an easier placeholder string (e.g. BaseURL), then when wsdl is being requested just read the WSDL file from the filesystem, dynamically replace all BaseURL string with the current actual URL and return it.

    Depending on what you are using as a library/framework there might be an out-of-the-box way to do the same thing with just a configuration, so investigate first.

    Good luck!