php soap客户端中的“字符串引用未设置为String实例”

时间:2014-10-03 06:36:39

标签: php web-services api exception soap

我试图为该服务编写一个soap客户端: http://link-products.chiangcn.com/APIService.asmx http://link-products.chiangcn.com/APIService.asmx?WSDL

我查询了服务提供的类型(_getTypes)。以下是' GetAuthorizedCategories'的类型结构。操作我试图执行:

Types:
struct GetAuthorizedCategories {
    string Request;
}

以下是我的PHP代码,它试图使用网络服务' GetAuthorizedCategories'操作:

<?php
$soap = new SoapClient('http://link-products.chiangcn.com/APIService.asmx?WSDL');
$arg = new stdClass;
$arg -> ClientId = 'ccd839ad-aef4-4748-a1c5-5235ef24f8ad';
$arg -> AccessToken = "155a0d0c2fea4e8a8c6da4bf5366241d";
$arguments = array('Request' => $arg);
$obj = $soap -> __soapCall('GetAuthorizedCategories', $arguments);
echo '<pre>';
var_dump($obj);
echo '</pre>';
?>

这是我从网络服务获得的例外情况。

object(stdClass)[3]
  public 'GetAuthorizedCategoriesResult' => string '<?xml version="1.0"?>
<Errors xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Code>0</Code>
  <Message>System.ArgumentNullException: String reference not set to an instance of a String.
Parameter name: s
   at System.Text.Encoding.GetBytes(String s)
   at PushData.Service.Utility.DeserializeXML[T](String xml)
   at PushData.Service.APIService.GetAuthorizedCategories(String Request)</Message>
</Errors>' (length=459)

这是我写的第一个SOAP客户端。任何帮助解决这个问题都很有用。

PS:这是webservice的文档 document

1 个答案:

答案 0 :(得分:0)

构建普通数组而不是使用stdClass实例。看看是否有效。

编辑

如果你还没试过。构建XML并将其用作$ arg。

你可以在这里看到额外的信息
http://link-products.chiangcn.com/APIService.asmx?op=GetAuthorizedCategories