在 WSDL 文件中为服务提供者使用动态 IP 地址
Using a dynamic IP address for the service provider in a WSDL file
我们是 运行 一个使用 PHP 的 soap 服务器,目前 IP 地址硬编码在 WSDL 文件中以提供操作等。但是,有计划将服务器打开较大的网络,它可能无法指定自己的 IP 地址,因此需要允许动态地址。
这里有几个使用此静态 IP 地址的示例。
<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">
和
<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>
有没有办法让 php 服务器在启动时用它的当前 IP 地址替换这些 IP 地址,或者只是一个可以放入其中的特殊值这样就可以了?
如果您希望客户端无需任何配置即可使用您的服务,则必须在请求时动态生成 WSDL。
许多平台都支持这种行为。以 Axis 为例:如果您在 http://Url/MyService
有一个服务,您也可以在 http://Url/MyService?wsdl
获得该服务的 WSDL。每次都会生成 WSDL。
我不知道你有什么工具可以使用,但即使使用普通 PHP,你也可以轻松实现相同的行为。首先,将 IP 替换为更简单的占位符字符串(例如 BaseURL
),然后在请求 wsdl 时,只需从文件系统读取 WSDL 文件,将所有 BaseURL
字符串动态替换为当前实际的 [=27] =] 和 return 它。
根据您使用的 library/framework,可能有一种开箱即用的方法可以仅通过配置来完成同样的事情,因此请先调查一下。
祝你好运!
另一个干净的解决方案是从客户端覆盖我们的网络服务的位置,例如:
$soapClient->__setLocation('http://www.example.com/soapservice');
我们是 运行 一个使用 PHP 的 soap 服务器,目前 IP 地址硬编码在 WSDL 文件中以提供操作等。但是,有计划将服务器打开较大的网络,它可能无法指定自己的 IP 地址,因此需要允许动态地址。
这里有几个使用此静态 IP 地址的示例。
<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">
和
<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>
有没有办法让 php 服务器在启动时用它的当前 IP 地址替换这些 IP 地址,或者只是一个可以放入其中的特殊值这样就可以了?
如果您希望客户端无需任何配置即可使用您的服务,则必须在请求时动态生成 WSDL。
许多平台都支持这种行为。以 Axis 为例:如果您在 http://Url/MyService
有一个服务,您也可以在 http://Url/MyService?wsdl
获得该服务的 WSDL。每次都会生成 WSDL。
我不知道你有什么工具可以使用,但即使使用普通 PHP,你也可以轻松实现相同的行为。首先,将 IP 替换为更简单的占位符字符串(例如 BaseURL
),然后在请求 wsdl 时,只需从文件系统读取 WSDL 文件,将所有 BaseURL
字符串动态替换为当前实际的 [=27] =] 和 return 它。
根据您使用的 library/framework,可能有一种开箱即用的方法可以仅通过配置来完成同样的事情,因此请先调查一下。
祝你好运!
另一个干净的解决方案是从客户端覆盖我们的网络服务的位置,例如:
$soapClient->__setLocation('http://www.example.com/soapservice');