【问题标题】:Exception “String reference not set to an instance of a String” in php soap clientphp soap客户端中的异常“字符串引用未设置为字符串的实例”
【发布时间】:2014-11-28 05:43:04
【问题描述】:

我正在尝试为以下服务编写一个肥皂客户端: http://link-products.chiangcn.com/APIService.asmx http://link-products.chiangcn.com/APIService.asmx?WSDL

我查询了服务提供的类型(_getTypes)。下面是我尝试执行的“GetAuthorizedCategories”操作的类型结构:

Types:
struct GetAuthorizedCategories {
    string Request;
}

下面是我尝试使用网络服务的“GetAuthorizedCategories”操作的 php 代码:

<?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的文档

【问题讨论】:

    标签: php web-services api exception soap


    【解决方案1】:

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

    编辑

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

    您可以在此处查看更多信息
    http://link-products.chiangcn.com/APIService.asmx?op=GetAuthorizedCategories

    【讨论】:

    • 你能做一个 var_dump($arg);然后在这里发布。
    • 感谢您的耐心。 array (size=1) 'Request' =&gt; array (size=2) 'ClientId' =&gt; string 'ccd839ad-aef4-4748-a1c5-5235ef24f8ad' (length=36) 'AccessToken' =&gt; string '155a0d0c2fea4e8a8c6da4bf5366241d' (length=32)
    猜你喜欢
    • 1970-01-01
    • 2020-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-07
    • 2011-08-19
    • 2021-08-23
    • 1970-01-01
    相关资源
    最近更新 更多