【问题标题】:Soap Client/Server "Invalid parameter (stdClass)"Soap 客户端/服务器“无效参数(stdClass)”
【发布时间】:2013-01-18 14:59:02
【问题描述】:

下面我包含了我的 PHP 客户端尝试与服务器通信的堆栈跟踪。客户端和服务器都读取 WSDL 文件文件,因此这部分无关紧要。

正如您在第二个堆栈跟踪数组项中看到的那样,我正在传递一个二维数组,但是当 SoapServer 执行它时,它是 __doRequest() 函数,该数组已被连接成一个单一的、无法管理的字符串。任何有关如何解决此问题的解决方案将不胜感激。

Internal Server ErrorArray
(
[0] => Array
    (
        [function] => __doRequest
        [class] => SoapClient
        [type] => ->
        [args] => Array
            (
                [0] => 
1Colby Meiertruetrue5510.517.55601000250020100151502015302000true10false0true23true12false152002020023.51031000.345231003.25520152.45258.52011.255152012

                [1] => http://192.168.1.120/test_soap/Client_Billing.php
                [2] => 
                [3] => 1
                [4] => 0
            )

    )

[1] => Array
    (
        [file] => /var/www/test_soap/client_avid_new.php
        [line] => 92
        [function] => __call
        [class] => SoapClient
        [type] => ->
        [args] => Array
            (
                [0] => CreatePlan
                [1] => Array
                    (
                        [0] => Array
                            (
                                [session-id] => 1
                                [plan] => Array
                                    (
                                        [name] => Colby Meier
                                        [is-public] => 1
                                        [active] => 1
                                        [country-id] => 5
                                        [setup-fee] => 5
                                        [base-rate] => 10.5
                                        [quarterly-per-month-rate] => 17.5
                                        [bi-annual-per-month-rate] => 56
                                        [annual-per-month-rate] => 0
                                        [blast-limit] => 1000
                                        [social-limit] => 2500
                                        [keyword-limit] => 20
                                        [vote-limit] => 100
                                        [auto-response-limit] => 15
                                        [text-2-screen-limit] => 150
                                        [survey-limit] => 20
                                        [trivia-limit] => 15
                                        [text-2-win-limit] => 30
                                        [mobile-website-limit] => 2000
                                        [enable-ftp] => 1
                                        [ftp-fee] => 10
                                        [enable-contact-manager] => 
                                        [contact-manager-fee] => 0
                                        [enable-mobile-website] => 1
                                        [mobile-website-fee] => 23
                                        [enable-listrak] => 1
                                        [listrak-fee] => 12
                                        [enable-url-qr] => 
                                        [url-qr-fee] => 15
                                        [mt-quota] => 200
                                        [mt-overage] => 20
                                        [mo-quota] => 200
                                        [mo-overage] => 23.5
                                        [keyword-quota] => 10
                                        [keyword-overage] => 3
                                        [mobile-website-quota] => 100
                                        [mobile-website-overage] => 0.3
                                        [keyword-campaign-quota] => 45
                                        [keyword-campaign-overage] => 23
                                        [vote-quota] => 100
                                        [vote-overage] => 3.25
                                        [auto-response-quota] => 5
                                        [auto-response-overage] => 20
                                        [text-2-screen-quota] => 15
                                        [text-2-screen-overage] => 2.45
                                        [survey-quota] => 25
                                        [survey-overage] => 8.5
                                        [trivia-quota] => 20
                                        [trivia-overage] => 11.25
                                        [text-2-win-quota] => 5
                                        [text-2-win-overage] => 15
                                        [social-quota] => 20
                                        [social-overage] => 12
                                    )

                            )

                    )

            )

    )

[2] => Array
    (
        [file] => /var/www/test_soap/client_avid_new.php
        [line] => 92
        [function] => CreatePlan
        [class] => SoapClient
        [type] => ->
        [args] => Array
            (
                [0] => Array
                    (
                        [session-id] => 1
                        [plan] => Array
                            (
                                [name] => Colby Meier
                                [is-public] => 1
                                [active] => 1
                                [country-id] => 5
                                [setup-fee] => 5
                                [base-rate] => 10.5
                                [quarterly-per-month-rate] => 17.5
                                [bi-annual-per-month-rate] => 56
                                [annual-per-month-rate] => 0
                                [blast-limit] => 1000
                                [social-limit] => 2500
                                [keyword-limit] => 20
                                [vote-limit] => 100
                                [auto-response-limit] => 15
                                [text-2-screen-limit] => 150
                                [survey-limit] => 20
                                [trivia-limit] => 15
                                [text-2-win-limit] => 30
                                [mobile-website-limit] => 2000
                                [enable-ftp] => 1
                                [ftp-fee] => 10
                                [enable-contact-manager] => 
                                [contact-manager-fee] => 0
                                [enable-mobile-website] => 1
                                [mobile-website-fee] => 23
                                [enable-listrak] => 1
                                [listrak-fee] => 12
                                [enable-url-qr] => 
                                [url-qr-fee] => 15
                                [mt-quota] => 200
                                [mt-overage] => 20
                                [mo-quota] => 200
                                [mo-overage] => 23.5
                                [keyword-quota] => 10
                                [keyword-overage] => 3
                                [mobile-website-quota] => 100
                                [mobile-website-overage] => 0.3
                                [keyword-campaign-quota] => 45
                                [keyword-campaign-overage] => 23
                                [vote-quota] => 100
                                [vote-overage] => 3.25
                                [auto-response-quota] => 5
                                [auto-response-overage] => 20
                                [text-2-screen-quota] => 15
                                [text-2-screen-overage] => 2.45
                                [survey-quota] => 25
                                [survey-overage] => 8.5
                                [trivia-quota] => 20
                                [trivia-overage] => 11.25
                                [text-2-win-quota] => 5
                                [text-2-win-overage] => 15
                                [social-quota] => 20
                                [social-overage] => 12
                            )

                    )

            )

    )

)

这是我调用客户端的代码:

$test = $client->CreatePlan(array("session-id"=>"1", "plan"=>$pa)); //$pa variable shown in stack trace

这是服务器上的相关代码:

 public function _checkArguments($arguments, $validParameters) {
    $variables = "";
    foreach ($arguments as $arg) {
        $type = gettype($arg);
        echo "type is ".$type;
        if ($type == "object") {
            $type = get_class($arg);
        }
        $variables .= "(".$type.")";
    }
    if (!in_array($variables, $validParameters)) {
        throw new Exception("Invalid parameter types: ".str_replace(")(", ", ", $variables));
    }
    return true;
}

/**
 * Service Call: CreatePlan
 * Parameter options:
 * (CreatePlan) parameters
 * @param mixed,... See function description for parameter options
 * @return CreatePlanResponse
 * @throws Exception invalid function signature messages
 */
public function CreatePlan($mixed = null) {
    $validParameters = array(
        "(CreatePlan)",
    );
    $args = func_get_args();
    echo "<pre>Args are: ".print_r($args)."</pre>";

    $this->_checkArguments($args, $validParameters);
    return $this->__soapCall("CreatePlan", $args);
}

如您所料,函数在func_get_args() 上失败。在过去的几天里,这一直让我完全发疯,所以任何建议都将不胜感激。

编辑:当我说它在func_get_args 上失败时,我的意思是我得到了一个空变量返回。所以在$args = func_get_args() 的情况下,$args 为空。

编辑 2:如果它有助于解决我的问题,这里是 Apache 服务器日志中的错误。

[error] [client 192.168.1.120] PHP Fatal error: Uncaught exception 'Exception' with message 'Invalid parameter types: (stdClass)' in /var/www/test_soap/Client_Billing.php:2200\nStack trace:\n#0 /var/www/test_soap/Client_Billing.php(2220): Client_Billing->_checkArguments(Array, Array)\n#1 [internal function]: Client_Billing->CreatePlan(Object(stdClass))\n#2 /var/www/test_soap/Client_Billing.php(2642): SoapServer->handle()\n#3 {main}\n thrown in /var/www/test_soap/Client_Billing.php on line 2200

编辑 3:根据要求,这是相关类型的 WSDL sn-p。

<complexType name="CreatePlanType"><!-- ns__CreatePlanType -->

   <sequence>
     <element name="name" type="xsd:string" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::name -->
     <element name="is-public" type="xsd:boolean" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::is_public -->
     <element name="active" type="xsd:boolean" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::active -->
     <element name="country-id" type="xsd:int" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::country_id -->
     <element name="setup-fee" type="xsd:float" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::setup_fee -->
     <element name="base-rate" type="xsd:float" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::base_rate -->
     <element name="quarterly-per-month-rate" type="xsd:float" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::quarterly_per_month_rate -->
     <element name="bi-annual-per-month-rate" type="xsd:float" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::bi_annual_per_month_rate -->
     <element name="annual-per-month-rate" type="xsd:float" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::annual_per_month_rate -->
     <element name="blast-limit" type="xsd:int" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::blast_limit -->
     <element name="social-limit" type="xsd:int" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::social_limit -->
     <element name="keyword-limit" type="xsd:int" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::keyword_limit -->
     <element name="vote-limit" type="xsd:int" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::vote_limit -->
     <element name="auto-response-limit" type="xsd:int" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::auto_response_limit -->
     <element name="text-2-screen-limit" type="xsd:int" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::text_2_screen_limit -->
     <element name="survey-limit" type="xsd:int" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::survey_limit -->
     <element name="trivia-limit" type="xsd:int" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::trivia_limit -->
     <element name="text-2-win-limit" type="xsd:int" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::text_2_win_limit -->
     <element name="mobile-website-limit" type="xsd:int" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::mobile_website_limit -->
     <element name="enable-ftp" type="xsd:boolean" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::enable_ftp -->
     <element name="ftp-fee" type="xsd:float" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::ftp_fee -->
     <element name="enable-contact-manager" type="xsd:boolean" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::enable_contact_manager -->
     <element name="contact-manager-fee" type="xsd:float" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::contact_manager_fee -->
     <element name="enable-mobile-website" type="xsd:boolean" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::enable_mobile_website -->
     <element name="mobile-website-fee" type="xsd:float" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::mobile_website_fee -->
     <element name="enable-listrak" type="xsd:boolean" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::enable_listrak -->
     <element name="listrak-fee" type="xsd:float" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::listrak_fee -->
     <element name="enable-url-qr" type="xsd:boolean" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::enable_url_qr -->
     <element name="url-qr-fee" type="xsd:float" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::url_qr_fee -->
     <element name="mt-quota" type="xsd:int" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::mt_quota -->
     <element name="mt-overage" type="xsd:float" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::mt_overage -->
     <element name="mo-quota" type="xsd:int" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::mo_quota -->
     <element name="mo-overage" type="xsd:float" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::mo_overage -->
     <element name="keyword-quota" type="xsd:int" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::keyword_quota -->
     <element name="keyword-overage" type="xsd:float" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::keyword_overage -->
     <element name="mobile-website-quota" type="xsd:int" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::mobile_website_quota -->
     <element name="mobile-website-overage" type="xsd:float" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::mobile_website_overage -->
     <element name="keyword-campaign-quota" type="xsd:int" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::keyword_campaign_quota -->
     <element name="keyword-campaign-overage" type="xsd:float" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::keyword_campaign_overage -->
     <element name="vote-quota" type="xsd:int" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::vote_quota -->
     <element name="vote-overage" type="xsd:float" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::vote_overage -->
     <element name="auto-response-quota" type="xsd:int" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::auto_response_quota -->
     <element name="auto-response-overage" type="xsd:float" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::auto_response_overage -->
     <element name="text-2-screen-quota" type="xsd:int" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::text_2_screen_quota -->
     <element name="text-2-screen-overage" type="xsd:float" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::text_2_screen_overage -->
     <element name="survey-quota" type="xsd:int" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::survey_quota -->
     <element name="survey-overage" type="xsd:float" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::survey_overage -->
     <element name="trivia-quota" type="xsd:int" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::trivia_quota -->
     <element name="trivia-overage" type="xsd:float" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::trivia_overage -->
     <element name="text-2-win-quota" type="xsd:int" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::text_2_win_quota -->
     <element name="text-2-win-overage" type="xsd:float" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::text_2_win_overage -->
     <element name="social-quota" type="xsd:int" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::social_quota -->
     <element name="social-overage" type="xsd:float" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlanType::social_overage -->
   </sequence>
  </complexType>
<element name="CreatePlan">
   <complexType>
    <sequence>
     <element name="session-id" type="xsd:string" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlan::session_id -->
     <element name="plan" type="ns:CreatePlanType" minOccurs="1" maxOccurs="1"/><!-- ns__CreatePlan::plan -->
    </sequence>
   </complexType>
  </element>

运行soap服务器的代码:

$server = new SoapServer("http://192.168.1.120/Client_Billing.wsdl");
$server->setClass("Client_Billing");
$server->handle();

【问题讨论】:

  • 将需要 WSDL 来回答问题。以及如何创建 SOAP 服务器的代码
  • @hek2mgl 现在在帖子中。谢谢。根据肥皂服务器,我使用 WSDLInterpreter 类从 WSDL 文件生成它。 $myWSDLlocation = 'http://192.168.1.120/Client_Billing.wsdl'; //where the file lives$wsdlInterpreter = new WSDLInterpreter($myWSDLlocation); //Load interpreter class$wsdlInterpreter-&gt;savePHP('/var/www/test_soap/'); //output PHP file location (directory only)
  • 我们能看到“无法管理的字符串”吗?我怀疑它是二维数组的序列化版本。
  • @IanAtkin 'unmanageable string' 位于 args[0] 的第一个堆栈跟踪项中。
  • @ColbyRMeier 我同意你使用“无法管理”的说法......!

标签: php soap apache2 soap-client


【解决方案1】:

您是否正在使用var_dump() 并查看浏览器中的输出?可能是浏览器隐藏了实际存在的 XML 标记!在页面上尝试“查看源代码”。

【讨论】:

  • 是的,我在 var_dump 和 print_r 之间交替来了解发生了什么。这些都没有真正帮助。它显示了已发送的内容,但没有显示为什么它显然要序列化我的数组。
【解决方案2】:

我认为它抓住了 PHP SoapServer 中对动态对象的特殊支持。如果可以,尝试用描述的类替换数组。

【讨论】:

  • 我也尝试使用名称类,但我仍然收到“找不到参数”或“内部服务器错误。无效参数类型:(stdClass)”的一致错误
【解决方案3】:

多次遇到soap和PHP问题后,我使用以下方法进行调试: 首先尝试回应您的回复:

echo htmlentities(var_dump($test,true));

如果没有任何内容,请继续执行此步骤: 找到soap错误的最好方法是在安装soap UI中使用嗅探器和soapUI,然后 创建第一个项目非常简单: http://www.soapui.org/Getting-Started/your-first-soapui-project.html

安装数据包嗅探器

创建项目并输入 WSDL 后,您将能够调用soap 服务方法,当您调用这些方法时,您必须手动输入参数。输入它们并运行函数,如果运行正常,则表示 PHP 端的某个地方存在错误,或者它隐藏在 HTML 注释中。 为了更好地了解错误在哪里,您必须使用嗅探器来捕捉您从肥皂服务获得的响应,运行嗅探器。 然后你必须分析你得到的输出。

【讨论】:

  • 检查了soapUI并尝试了htmlentities建议。一切都无济于事。当我基于soapUI内部的WSDL执行标准请求时,我在编辑2中得到了上面列出的错误。无论是什么导致它尝试形成stdClass都会导致内部服务器错误并阻止任何进一步的进展。
【解决方案4】:

根据我的经验,在 PHP 中调试 web 服务是一件痛苦的事……但如果可以的话,我会尽力给你一些帮助。

您使用的 WSDLInterpreter 是什么?那是您开发的某个第三方类或某些包装器,只是为了在您创建客户端时做一些额外的事情吗?你有什么理由不使用SoapClient

您是否尝试用您正在使用并在 WSDL 中提及的类的对象的实际实例替换您发送的那些数组?

【讨论】:

  • 非常感谢您的帮助。我正在使用找到here 的WSDLInterpreter 类我正在为我的客户端使用SoapClient,为我的服务器使用SoapServer(不是PEAR SOAP)。我尝试用对象类替换数组也无济于事。似乎无论我做什么,我都会留下两个错误之一。 “找不到参数”或“无效的参数类型(stdClass)”。
【解决方案5】:

所以万一有人还在关注这个帖子。我发现了问题所在,我希望我可以说我也不是一个完全没有看到它的白痴,但我不倾向于养成撒谎的习惯。

整个问题源于我的“服务器”类扩展了我的“客户端”类,并从soap调用本身递归调用__soapCall()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-01
    • 2011-10-11
    • 2019-05-20
    相关资源
    最近更新 更多