doujiushi9007 2019-05-03 15:26
浏览 337

SOAP API错误:未将对象引用设置为对象的实例

I'm trying to pull data from a SOAP API on a Wordpress site. I'm using the PHP SoapClient library.

I've scoured the internet over the past week trying every possible solution to this problem I can find, including trying other libraries, with no luck. I haven't even gotten to the point where I can pull data, I'm just trying to login to this service, which I can confirm the login and other functions work through thirdparty applications.

I've also tried refactoring my code into it's own class and calling things that way, but the same issues occur.

I keep getting the same error back no matter what I try:

Fatal error: Uncaught SoapFault exception: [soap:Server] System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object. at NjoynDataGateway.Login(String pr_UserName, String pr_Password, Boolean pr_AbortExistingSession) --- End of inner exception stack trace

This is the code I'm using:

$url = 'https://qa1.njoyn.com/CL4/net/WebService/NjoynDataExport.asmx?wsdl';
$username = 'username';
$password = 'password';
$abort_session = true;
$namespace = "http://njoyn.com/";

$soap_client = new SoapClient($url);

// Body of the Soap Header.
$headerbody = [
    'pr_UserName' => $username,
    'pr_Password' => $password,
];

// Create Soap Header.
$header = new SOAPHeader($namespace, 'AuthHeader', $headerbody);
$soap_client->__setSoapHeaders($header);

$result = $soap_client->__SoapCall('Login', [
    'pr_UserName' => $username,
    'pr_Password' => $password,
    'pr_AbortExistingSession' => $abort_session,
]);

var_dump($result);

Expected results would be something that isn't an error to start with. According to their documentation, the login method should return true.

  • 写回答

1条回答 默认 最新

  • dongquan0024 2019-05-15 17:25
    关注

    For anyone who's seeing this, I wasn't able to get the SOAP API working. I tried everything I could think of. I tried dozens of different coding approaches, tried connecting to other SOAP APIs which worked with no issues. I tried many online SOAP API clients, all of which failed except for one.

    The Object reference not set to an instance of an object error is a response from their API. All of the online SOAP clients I tried that failed were using the PHP SoapClient library and one used a Node.JS library. The one that worked was http://www.soapclient.com/soapTest.html which uses a C++ library. So there's potentially some sort of issue with the way their API is interacting with some of these libraries. I'm not familiar with the intricacies of SOAP at all so this is as far as I've gotten. Fortunately for me, they were able to provide me a link where I could scrape the data I needed from.

    Hopefully others that run into this can find a non-SOAP approach to achieve their issue. If not, I'd start looking into, or contacting them to look into, issues on their end.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?