PHP SoapClient creating XML references for identical elements, makes it unacceptable for service

前端 未结 4 989
北恋
北恋 2020-12-19 08:17

I am working on a SOAP client in PHP, and the calls are going through to the service fine, with the exception of calls where there are elements that are identical to each ot

4条回答
  •  醉酒成梦
    2020-12-19 08:38

    Hello You can try this fix:

    You need to extends the SoapClient and fix the generated request:

    You need to add the tags that are causing problems here

    $tags = ['Tag1', 'Tag2', 'Tag3'];
    

    And then use the MySoapClient instead of SoapClient

    class MySoapClient extends SoapClient {
    
    public function __construct($a, $b){
        parent::__construct($a, $b);
    }
    
    public function __doRequest($request, $location, $action, $version, $one_way = 0) {
    
        $tags = ['Tag1', 'Tag2', 'Tag3'];
        foreach($tags as $tag){
            if (preg_match("~(.+)~ismU", $request, $matches)) {
                $ref = $matches[1];
    
                $request = str_replace([' id="ref'.$ref.'"'], '', $request);
    
                $tagValue = "{$matches[2]}";
                $request = str_replace("", $tagValue, $request);
            }
        }
        return parent::__doRequest($request, $location, $action, $version);
    }
    

    }

提交回复
热议问题