PHP中的soap,无法使其工作

时间:2014-09-05 02:41:34

标签: php web-services soap

我收到此错误

Server was unable to process request. ---> Object reference not set to an instance of an object.   

我正在尝试学习如何使用php中的soap服务,我已经用c#完成了这个并尝试了新的东西。但我得到了上述错误,我不知道为什么,这是我试图访问的电话" call"

如果对某事有帮助,请附上c#。

谢谢!

代码php

<?php
        try{
            $opts = array(
                'https'=>array(
                    'user_agent' => 'PHPSoapClient'
                    ));
            $context = stream_context_create($opts);
            $userC = array("UserName"=>"pato.api",
                            "Password"=>"745477",
                            "ApplicationID"=>getGUID(),
                            "ClientID"=>getGUID());
            $Session = array("SessionId"=>getGUID());
            $soap_client = new SoapClient("https://onlineavl2api-mx.navmanwireless.com/onlineavl/api/V1.3/service.asmx?WSDL",array("stream_context" => $context,"cache_wsdl" => "WSDL_CACHE_NONE"));
            $request = array("UserCredentials"=>$userC,"Session"=>$Session,"IPAdress"=>"0.0.0.0","ClockVerificationUtc"=>date("Y-m-d") . 'T' . date("H:i:s"));
            $vec = array("request"=>$request);
            $quote = $soap_client->DoLogin($vec);
            echo $quote->DoLoginResponse;
        } catch (SoapFault $ex) {
            echo $ex->getMessage();
        }


        function getGUID(){
            if (function_exists('com_create_guid')){
                return com_create_guid();
            }else{
                mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
                $charid = strtoupper(md5(uniqid(rand(), true)));
                $hyphen = chr(45);// "-"
                $uuid =substr($charid, 0, 8).$hyphen
                    .substr($charid, 8, 4).$hyphen
                    .substr($charid,12, 4).$hyphen
                    .substr($charid,16, 4).$hyphen
                    .substr($charid,20,12);
        return $uuid;
            }
        }

        ?>

代码C#

public DoLoginResponse Login()
        {
            var Client = new ServiceSoapClient();
            var request = new DoLoginRequest()
            {
                Session = new SessionInfo()
                {
                    SessionId = Guid.NewGuid()
                },
                UserCredential = new UserCredentialInfo()
                {
                    UserName = _User,
                    Password = _Password,
                    ApplicationID = Guid.NewGuid(),
                    ClientID = Guid.NewGuid()
                }
            };
            var response = new DoLoginResponse();

1 个答案:

答案 0 :(得分:0)

使用您的php脚本上的以下更新进行检查[使用 UserCredential ],

$request = array("UserCredential"=>$userC,"Session"=>$Session,"IPAdress"=>"127.0.0.0","ClockVerificationUtc"=>date("Y-m-d") . 'T' . date("H:i:s"));

此外,您还缺少此“取消”中的“ClientVersion”参数,

    $userC = array("UserName"=>"pato.api",
                "Password"=>"745477",
                "ApplicationID"=>getGUID(),
                "ClientID"=>getGUID(),
                "ClientVersion"=>"your_client_version"
                );