问题描述
我有一个过去 5 年都在使用的 PHP Web 服务 API。
我被要求对它进行 dockerize。所以我已经设置了我的 docker 容器。
除了我的肥皂服务器返回的响应之外,所有代码都可以正常工作。
所有代码都是一样的,没有任何变化,但现在 API 在 docker 中运行。
在 docker 之外运行 API 时,我收到以下对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,trim($keyName),$ns);
$dataInStruct[] = new SoapVar(trim($val),trim($valName),$ns);
$paramStruct[] = new SoapVar($dataInStruct,SOAP_ENC_OBJECT,$parentName,$ns);
}
$dataStruct = new SoapVar($paramStruct,$ns);
return $dataStruct;
}
error_log 输出为 Process Pair key-val : status - SUCCESS
构造最终的soap响应并返回它的函数是:
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,'AdditionalResponseParams',$this->ns);
} else {
$dataInStruct[] = new SoapVar(null,$this->ns);
}
$dataStruct[] = new SoapVar($dataInStruct,'ResponseInfo',$this->ns);
$rspObj = new SoapVar($dataStruct,'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 有关 我发现了同样的问题 here 并得到了回答,但我发现它有点晚了