webman里写SoapServer没有执行handle方法

venchi

问题描述

类似案例 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 方法也捕获不到数据。

操作系统环境及workerman/webman等具体版本

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
1397 2 0
2个回答

SillyDog

看下 webman 文档的响应部份
https://www.workerman.net/doc/webman/response.html

  • venchi 2024-02-19

    尝试过ob_start + ob_get_clean 还是获取不到,respons + header也不行

  • 27025011 2024-02-20

    handle()方法代码提供一下

  • venchi 2024-02-21

    这个是php的扩展,soap。可以在php.ini里开启

SillyDog

请看vcr

// 控制器方法内
$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";
  • venchi 2024-02-21
    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也是一样

  • SillyDog 2024-02-21

    尝试把我那段处理 请求参数的代码加一下试试
    $result = $request->rawBody();
    if (is_array($result)) {
    $result = implode(" ", $result);
    }
    $ss->handle($result);

  • venchi 2024-02-23

    控制台输出

    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>

    网页显示 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 ;
        }
×
🔝