使用PHP SOAP客户端进行枚举验证,导致空白请求

时间:2013-12-20 01:29:55

标签: php web-services soap wsdl

我在使用包含受限枚举的参数进行SOAP调用时遇到问题。这是我的WSDL的相关部分(方法,输入类型和枚举):

<s:element name="createMagnetMailMessage">
    <s:complexType>
      <s:sequence>
        <s:element minOccurs="0" maxOccurs="1" name="message" type="tns:MessageDetails" />
      </s:sequence>
    </s:complexType>
  </s:element>

  <s:complexType name="MessageDetails">
    <s:sequence>
      <s:element minOccurs="1" maxOccurs="1" name="characterSet" type="tns:CharacterSet" />
    </s:sequence>
  </s:complexType>

  <s:simpleType name="CharacterSet">
    <s:restriction base="s:string">
      <s:enumeration value="Western" />
      <s:enumeration value="International" />
    </s:restriction>
  </s:simpleType>
</s:element>

这是我用来调用SOAP方法的代码:

$options = array('trace' => true, 'exceptions' => true, 'connection_timeout' => 60);
$client = new SoapClient('https://example.com/mmapi.asmx?wsdl', $options);

// ... stuff to add authentication header ...

$data = array();
$data['characterSet'] = 'International';

try {
    $request = $client->createMagnetMailMessage($data);
} catch(Exception $ex) {
    echo 'ERROR: '.$ex->getMessage();
}

var_dump($client->__getLastRequest());

最后,这是发送的实际请求(注意空体):

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.magnetmail.net/">
  <SOAP-ENV:Header>
    <ns1:mmAuthHeader>
      <ns1:sessionId>ABC123</ns1:sessionId>
      <ns1:user_id>USER</ns1:user_id>
    </ns1:mmAuthHeader>
  </SOAP-ENV:Header>
  <SOAP-ENV:Body>
    <ns1:createMagnetMailMessage/>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

显然当发送给方法的数据不符合WSDL的约束时,PHP的SOAP客户端什么都不发送?即便如此,我发送的数据对我来说也是有效的。我错过了什么?

0 个答案:

没有答案