类似案例 https://www.workerman.net/q/9010
代码
public function serv(Request $request)
{
$wsdl_path = public_path().DIRECTORY_SEPARATOR.'webman.wsdl';
try{
$options = array(
'uri' => 'urn:mywebservice',
'location' => 'http://127.0.0.1:8787/soap/serv'
);
$serv = new SoapServer($wsdl_path);
$serv->setObject(new \app\SoapServ());
var_dump($wsdl_path, file_get_contents($wsdl_path));
// readfile($wsdl_path);
$serv->handle();
}catch(\Throwable $th) {
var_dump($th->getMessage());
}
return ;
}
网页源代码
控制台打印
string(49) "D:\repo\php\interfacems\webman\public\webman.wsdl"
string(2446) "<?xml version="1.0"?>
<definitions name="MyWebService"
targetNamespace="urn:mywebservice"
xmlns:tns="urn:mywebservice"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<xsd:schema targetNamespace="urn:mywebservice">
<xsd:element name="sayHello">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="sayHelloResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="return" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</types>
<message name="sayHelloRequest">
<part name="parameters" element="tns:sayHello"/>
</message>
<message name="sayHelloResponse">
<part name="parameters" element="tns:sayHelloResponse"/>
</message>
<portType name="MyWebServicePortType">
<operation name="sayHello">
<input message="tns:sayHelloRequest"/>
<output message="tns:sayHelloResponse"/>
</operation>
</portType>
<binding name="MyWebServiceBinding" type="tns:MyWebServicePortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="sayHello">
<soap:operation soapAction="urn:mywebservice:sayHello"/>
<input>
<soap:body use="encoded" namespace="urn:mywebservice" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="urn:mywebservice" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="MyWebServiceService">
<port name="MyWebServicePort" binding="tns:MyWebServiceBinding">
<soap:address location="http://127.0.0.1:8787/soap/serv"/>
</port>
</service>
</definitions>
"
页面访问添加?wsdl
参数,正常会返回webman.wsdl
的内容。但是webman这里没有返回,使用ob_start
ob_get_clean
方法也捕获不到数据。
windows环境
webman版本:"workerman/webman-framework": "^1.5.0"
php版本、扩展:
PS D:\repo\php\interfacems> php -v
PHP 8.3.0 (cli) (built: Nov 21 2023 17:48:00) (NTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.3.0, Copyright (c) Zend Technologies
PS D:\repo\php\interfacems> php --ri soap
soap
Soap Client => enabled
Soap Server => enabled
Directive => Local Value => Master Value
soap.wsdl_cache_enabled => On => On
soap.wsdl_cache_dir => /tmp => /tmp
soap.wsdl_cache_ttl => 86400 => 86400
soap.wsdl_cache => 1 => 1
soap.wsdl_cache_limit => 5 => 5
看下 webman 文档的响应部份
https://www.workerman.net/doc/webman/response.html
尝试过ob_start + ob_get_clean 还是获取不到,respons + header也不行
handle()方法代码提供一下
这个是php的扩展,soap。可以在php.ini里开启
请看vcr
还是没有返回,有试过ob_get_content+ob_end_clean也是一样
尝试把我那段处理 请求参数的代码加一下试试
$result = $request->rawBody();
if (is_array($result)) {
$result = implode(" ", $result);
}
$ss->handle($result);
控制台输出
网页显示 ERR_EMPTY_RESPONSE
server方法: