類似案例 http://www.wtbis.cn/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 ;
}
網(wǎng)頁源代碼
控制臺打印
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
參數(shù),正常會返回webman.wsdl
的內(nèi)容。但是webman這里沒有返回,使用ob_start
ob_get_clean
方法也捕獲不到數(shù)據(jù)。
windows環(huán)境
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 文檔的響應(yīng)部份
http://www.wtbis.cn/doc/webman/response.html
請看vcr
// 控制器方法內(nèi)
$result = $request->rawBody();
if (is_array($result)) {
$result = implode(" ", $result);
}
Log::info($result);
$ss = new \SoapServer(null, array('uri' => 'sampleA'));
$ss->setObject(new testA());
ob_start();
$ss->handle($result);
$result = ob_get_clean();
return response($result);
// 客戶端
$client = new \SoapClient(null, array(
'location' => 'http://127.0.0.1:8787',
'uri' => 'sampleA'
));
echo json_encode($client->sayHi('Taylor,Swift'), JSON_UNESCAPED_UNICODE) . "\n";
echo "<br/>" . "\n";
echo json_encode($client->add(1, 2), JSON_UNESCAPED_UNICODE) . "\n";
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:8086/soap/serv'
);
$serv = new \SoapServer($wsdl_path);
ob_start();
$serv->setObject(new \app\SoapServ());
// var_dump($wsdl_path, file_get_contents($wsdl_path));
// readfile($wsdl_path);
$serv->handle();
$ret = ob_get_clean();
return response($ret);
}catch(\Throwable $th) {
var_dump($th->getMessage());
}
return ;
}
還是沒有返回,有試過ob_get_content+ob_end_clean也是一樣
嘗試把我那段處理 請求參數(shù)的代碼加一下試試
$result = $request->rawBody();
if (is_array($result)) {
$result = implode(" ", $result);
}
$ss->handle($result);
控制臺輸出
Worker[288] process terminated
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Client</faultcode><faultstring>Bad Request</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
網(wǎng)頁顯示 ERR_EMPTY_RESPONSE
server方法:
public function serv(Request $request)
{
$wsdl_path = public_path().DIRECTORY_SEPARATOR.'webman.wsdl';
try{
$result = $request->rawBody();
if (is_array($result)) {
$result = implode(" ", $result);
}
$options = array(
'uri' => 'urn:mywebservice',
'location' => 'http://127.0.0.1:8086/soap/serv'
);
$serv = new \SoapServer($wsdl_path);
ob_start();
$serv->setObject(new \app\SoapServ());
// var_dump($wsdl_path, file_get_contents($wsdl_path));
// readfile($wsdl_path);
$serv->handle($result);
$ret = ob_get_clean();
return response($ret);
}catch(\Throwable $th) {
var_dump($th->getMessage());
}
return ;
}