PHP SoapClient,Ruby wash_out,当传递参数时:类 stdClass 的对象无法转换为字符串


PHP SoapClient, Ruby wash_out, when passing params: Object of class stdClass could not be converted to string

这是我的PHP:

    $url = "http://localhost:3000/api/wsdl";
    $client = new SoapClient($url);
    $params->a  = 'a Value';
    $params->b  = 'another Value';
    $client->AnOperation($params);

这是一个 ruby 控制器,它使用了我用来创建 SOAP 服务器的 wash_out gem:

require "wash_out/soap"
class ApiController < ApplicationController
  soap_service namespace: 'urn:WashOut'
  soap_action "AnOperation",
              :args   => { :a => :string, :b => :string },
              :return => :string
  def AnOperation
    render :soap => "done"
  end
  before_filter :dump_parameters
  def dump_parameters
    logger.debug params.inspect
  end
end

下面是生成的 WSDL:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:WashOut" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="api" targetNamespace="urn:WashOut">
  <types>
    <schema targetNamespace="urn:WashOut" xmlns="http://www.w3.org/2001/XMLSchema">
    </schema>
  </types>
  <portType name="api_port">
    <operation name="AnOperation">
      <input message="tns:AnOperation"/>
      <output message="tns:AnOperation_response"/>
    </operation>
  </portType>
  <binding name="api_binding" type="tns:api_port">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="AnOperation">
      <soap:operation soapAction="AnOperation"/>
      <input>
        <soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:WashOut"/>
      </input>
      <output>
        <soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:WashOut"/>
      </output>
    </operation>
  </binding>
  <service name="service">
    <port name="api_port" binding="tns:api_binding">
      <soap:address location="http://localhost:3000/api/action"/>
    </port>
  </service>
  <message name="AnOperation">
    <part name="a" type="xsd:string"/>
    <part name="b" type="xsd:string"/>
  </message>
  <message name="AnOperation_response">
    <part name="value" type="xsd:string"/>
  </message>
</definitions>

当我运行PHP时,我得到"类标准类的对象无法转换为字符串"。

似乎是两件事:

1) 我的 WSDL 缓存为 PHP 打开了。 它缓存了我在 ruby 中开发的旧版本的 WSDL。 您可以在运行时级别或配置级别关闭缓存。

2) 我的请求对象结构已关闭。 我通过带有键/值对的对象提交参数,但这在 WSDL 中是意料之中的。 我调整了 WSDL 中操作的消息,以采用包含我正在传递的参数的"部分"。