php docker 内的 soap 服务器没有 return 响应
php soap server inside docker does not return response
我有一个 php Web 服务 API 在过去 5 年里一直在工作。
我被要求 docker 化它。所以我已经设置了我的 docker 容器。
所有代码都工作正常,除了响应我的 soap 服务器 returns.
所有的代码都是一样的,没有任何改变,只是现在 API 是 docker.
里面的 运行
当 运行 API 在 docker 之外时,我得到以下对 soapUI(或 curl)的响应:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://netmedservice.com/soap/executeCommand">
<SOAP-ENV:Body>
<ns1:executeCommandResponse>
<executeCommandResponse>
<ns1:ResponseInfo>
<ns1:MainResponseParams>
<ns1:Attributes>
<ns1:Name>status</ns1:Name>
<ns1:Value>SUCCESS</ns1:Value>
</ns1:Attributes>
</ns1:MainResponseParams>
<ns1:AdditionalResponseParams/>
</ns1:ResponseInfo>
</executeCommandResponse>
</ns1:executeCommandResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
这是我能得到的最简单的回复。
docker 中的相同响应是这样的:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://netmedservice.com/soap/executeCommand">
<SOAP-ENV:Body>
<ns1:executeCommandResponse>
<executeCommandResponse/>
</ns1:executeCommandResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
如您所见,我具有 wsdl 中描述的结构,但从 xsd 中我只得到没有数据的第一个元素。
在我的代码中,我尝试调试并查看是否有数据。
我有一个函数可以获取数组中的数据并创建相应的 soap :
public static function soapEncodeNameValues(array $data, $soapContainer, $ns, $parentName="Attributes", $keyName="Name", $valName="Value") {
$dataStruct = new stdClass();
$paramStruct = new ArrayObject;
foreach ($data as $key => $val) {
error_log("Process Pair key-val : " . trim($key) . " - " . trim($val) . "\n");
$dataInStruct = new ArrayObject();
$dataInStruct[] = new SoapVar(trim($key), XSD_STRING, null, null, trim($keyName), $ns);
$dataInStruct[] = new SoapVar(trim($val), XSD_STRING, null, null, trim($valName), $ns);
$paramStruct[] = new SoapVar($dataInStruct, SOAP_ENC_OBJECT, null, null, $parentName, $ns);
}
$dataStruct = new SoapVar($paramStruct, SOAP_ENC_OBJECT, null, null, $soapContainer, $ns);
return $dataStruct;
}
error_log 输出是 Process Pair key-val : status - SUCCESS
构建最终 soap 响应的函数 returns 是 :
function constructResponse($response) {
$rspObj = new stdClass();
$dataStruct = new ArrayObject;
$dataInStruct = new ArrayObject;
$addParams = new ArrayObject;
$dataInStruct[] = parser::soapEncodeNameValues($response->MainResponseParams, 'MainResponseParams', $this->ns);
if ($response->AdditionalResponseParams !== null) {
foreach ($response->AdditionalResponseParams as $addParam) {
$addParams[] = parser::soapEncodeNameValues($addParam, 'Lines', $this->ns, 'Attributes');
}
$dataInStruct[] = new SoapVar($addParams, SOAP_ENC_OBJECT, null, null, 'AdditionalResponseParams', $this->ns);
} else {
$dataInStruct[] = new SoapVar(null, SOAP_ENC_OBJECT, null, null, 'AdditionalResponseParams', $this->ns);
}
$dataStruct[] = new SoapVar($dataInStruct, SOAP_ENC_OBJECT, null, null, 'ResponseInfo', $this->ns);
$rspObj = new SoapVar($dataStruct, SOAP_ENC_OBJECT, null, null, 'executeCommandResponse', null);
error_log(print_r($rspObj,1));
return $rspObj;
}
上面编码的 SOAP 的错误日志是:
SoapVar Object
(
[enc_type] => 301
[enc_value] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[0] => SoapVar Object
(
[enc_type] => 301
[enc_value] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[0] => SoapVar Object
(
[enc_type] => 301
[enc_value] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[0] => SoapVar Object
(
[enc_type] => 101
[enc_value] => status
[enc_name] => Name
[enc_namens] => http://netmedservice.com/soap/executeCommand
)
[1] => SoapVar Object
(
[enc_type] => 101
[enc_value] => SUCCESS
[enc_name] => Value
[enc_namens] => http://netmedservice.com/soap/executeCommand
)
)
)
[enc_name] => Attributes
[enc_namens] => http://netmedservice.com/soap/executeCommand
)
[enc_name] => MainResponseParams
[enc_namens] => http://netmedservice.com/soap/executeCommand
)
[1] => SoapVar Object
(
[enc_type] => 301
[enc_name] => AdditionalResponseParams
[enc_namens] => http://netmedservice.com/soap/executeCommand
)
)
)
[enc_name] => ResponseInfo
[enc_namens] => http://netmedservice.com/soap/executeCommand
)
)
)
[enc_name] => executeCommandResponse
)
最后 xsd 模式中的响应是:
<xsd:complexType name="executeCommandResponse">
<xsd:sequence>
<xsd:element name="ResponseInfo" minOccurs="0" maxOccurs="1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="MainResponseParams" minOccurs="0" maxOccurs="1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Attributes" type="exc:AttributesList" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="AdditionalResponseParams" minOccurs="0" maxOccurs="1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Lines" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Attributes" type="exc:AttributesList" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
谢谢
经过大量测试和查找,问题解决。
这不是 docker,它与 docker 的 php 7.4 版本有关
我发现了同样的问题 并得到了解答,但我发现它有点晚了
我有一个 php Web 服务 API 在过去 5 年里一直在工作。
我被要求 docker 化它。所以我已经设置了我的 docker 容器。
所有代码都工作正常,除了响应我的 soap 服务器 returns.
所有的代码都是一样的,没有任何改变,只是现在 API 是 docker.
里面的 运行 当 运行 API 在 docker 之外时,我得到以下对 soapUI(或 curl)的响应:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://netmedservice.com/soap/executeCommand">
<SOAP-ENV:Body>
<ns1:executeCommandResponse>
<executeCommandResponse>
<ns1:ResponseInfo>
<ns1:MainResponseParams>
<ns1:Attributes>
<ns1:Name>status</ns1:Name>
<ns1:Value>SUCCESS</ns1:Value>
</ns1:Attributes>
</ns1:MainResponseParams>
<ns1:AdditionalResponseParams/>
</ns1:ResponseInfo>
</executeCommandResponse>
</ns1:executeCommandResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
这是我能得到的最简单的回复。 docker 中的相同响应是这样的:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://netmedservice.com/soap/executeCommand">
<SOAP-ENV:Body>
<ns1:executeCommandResponse>
<executeCommandResponse/>
</ns1:executeCommandResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
如您所见,我具有 wsdl 中描述的结构,但从 xsd 中我只得到没有数据的第一个元素。 在我的代码中,我尝试调试并查看是否有数据。 我有一个函数可以获取数组中的数据并创建相应的 soap :
public static function soapEncodeNameValues(array $data, $soapContainer, $ns, $parentName="Attributes", $keyName="Name", $valName="Value") {
$dataStruct = new stdClass();
$paramStruct = new ArrayObject;
foreach ($data as $key => $val) {
error_log("Process Pair key-val : " . trim($key) . " - " . trim($val) . "\n");
$dataInStruct = new ArrayObject();
$dataInStruct[] = new SoapVar(trim($key), XSD_STRING, null, null, trim($keyName), $ns);
$dataInStruct[] = new SoapVar(trim($val), XSD_STRING, null, null, trim($valName), $ns);
$paramStruct[] = new SoapVar($dataInStruct, SOAP_ENC_OBJECT, null, null, $parentName, $ns);
}
$dataStruct = new SoapVar($paramStruct, SOAP_ENC_OBJECT, null, null, $soapContainer, $ns);
return $dataStruct;
}
error_log 输出是 Process Pair key-val : status - SUCCESS
构建最终 soap 响应的函数 returns 是 :
function constructResponse($response) {
$rspObj = new stdClass();
$dataStruct = new ArrayObject;
$dataInStruct = new ArrayObject;
$addParams = new ArrayObject;
$dataInStruct[] = parser::soapEncodeNameValues($response->MainResponseParams, 'MainResponseParams', $this->ns);
if ($response->AdditionalResponseParams !== null) {
foreach ($response->AdditionalResponseParams as $addParam) {
$addParams[] = parser::soapEncodeNameValues($addParam, 'Lines', $this->ns, 'Attributes');
}
$dataInStruct[] = new SoapVar($addParams, SOAP_ENC_OBJECT, null, null, 'AdditionalResponseParams', $this->ns);
} else {
$dataInStruct[] = new SoapVar(null, SOAP_ENC_OBJECT, null, null, 'AdditionalResponseParams', $this->ns);
}
$dataStruct[] = new SoapVar($dataInStruct, SOAP_ENC_OBJECT, null, null, 'ResponseInfo', $this->ns);
$rspObj = new SoapVar($dataStruct, SOAP_ENC_OBJECT, null, null, 'executeCommandResponse', null);
error_log(print_r($rspObj,1));
return $rspObj;
}
上面编码的 SOAP 的错误日志是:
SoapVar Object
(
[enc_type] => 301
[enc_value] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[0] => SoapVar Object
(
[enc_type] => 301
[enc_value] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[0] => SoapVar Object
(
[enc_type] => 301
[enc_value] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[0] => SoapVar Object
(
[enc_type] => 101
[enc_value] => status
[enc_name] => Name
[enc_namens] => http://netmedservice.com/soap/executeCommand
)
[1] => SoapVar Object
(
[enc_type] => 101
[enc_value] => SUCCESS
[enc_name] => Value
[enc_namens] => http://netmedservice.com/soap/executeCommand
)
)
)
[enc_name] => Attributes
[enc_namens] => http://netmedservice.com/soap/executeCommand
)
[enc_name] => MainResponseParams
[enc_namens] => http://netmedservice.com/soap/executeCommand
)
[1] => SoapVar Object
(
[enc_type] => 301
[enc_name] => AdditionalResponseParams
[enc_namens] => http://netmedservice.com/soap/executeCommand
)
)
)
[enc_name] => ResponseInfo
[enc_namens] => http://netmedservice.com/soap/executeCommand
)
)
)
[enc_name] => executeCommandResponse
)
最后 xsd 模式中的响应是:
<xsd:complexType name="executeCommandResponse">
<xsd:sequence>
<xsd:element name="ResponseInfo" minOccurs="0" maxOccurs="1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="MainResponseParams" minOccurs="0" maxOccurs="1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Attributes" type="exc:AttributesList" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="AdditionalResponseParams" minOccurs="0" maxOccurs="1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Lines" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Attributes" type="exc:AttributesList" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
谢谢
经过大量测试和查找,问题解决。
这不是 docker,它与 docker 的 php 7.4 版本有关
我发现了同样的问题