1

我在我的 php 页面中调用 Web 服务。Web 服务在 C# 中。当我尝试使用肥皂客户端对象调用方法时,它会显示如下错误:

System.NullReferenceException: Object reference not set to an instance of an object.

我用来调用 Web 服务方法的代码是:

 $Username = "username";
 $Password = "password";
 $LifetimeRequest = 60*60*24;


$soap_data = array(
   'Username' => $Username,
   'Password' => $Password,
   'LifetimeRequest' => $LifetimeRequest
);
$client = new SoapClient('http://50.56.173.161:8502/AdomniService.svc?wsdl');
$response = $client->ClientLogin($soap_data);
var_dump($response);

当我使用var_dump它时,它会显示如下输出:

object(stdClass)#2 (1) {
  ["ClientLoginResult"]=>
  object(stdClass)#3 (3) {
    ["Error"]=>
    object(stdClass)#4 (5) {
      ["Private"]=>
      float(2)
      ["Public"]=>
      int(1)
      ["Details"]=>
      string(284) "System.NullReferenceException: Object reference not set to an instance of an object.
   at Adomni.AdomniService.ClientLogin(ClientLoginRequest request) in C:\Users\megiddo\Documents\Visual Studio 2010\Projects\Adomni\AdOmniAPIService\AdomniService\AdomniClientService.svc.cs:line 107"
      ["ErrorCode"]=>
      int(0)
      ["ErrorMessage"]=>
      NULL
    }
    ["Status"]=>
    int(-1)
    ["Token"]=>
    object(stdClass)#5 (8) {
      ["Private"]=>
      float(2)
      ["Public"]=>
      int(1)
      ["EventNotificationUri"]=>
      NULL
      ["IsManager"]=>
      bool(false)
      ["LifetimeRequest"]=>
      int(0)
      ["Password"]=>
      NULL
      ["TokenId"]=>
      int(0)
      ["UserName"]=>
      NULL
    }
  }
}

谁能告诉我我在这里做错了什么?提前致谢。

在 C# 中使用的代码如下:

using System; 
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Web.Security;
using System.IO;
using System.Data;
using AdOmniWebPortal.AdOmniService;

namespace AdOmniWebPortal
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void AdOmniLogin_Authenticate(object sender, AuthenticateEventArgs e)
        {
            AdomniServiceClient Client = new AdomniServiceClient();
            LoginRequest LoginRequest = new LoginRequest();
            LoginResponse LoginResponse = new LoginResponse();

            LoginRequest.Username = AdOmniLogin.UserName;
            LoginRequest.Password = AdOmniLogin.Password;
            LoginRequest.LifetimeRequest = 60*60*24;
            //This guy will be changed
            LoginRequest.EventNotificationURL = new Uri("http://herp-a-derp.com/awesome.html");

            LoginResponse = Client.Login(LoginRequest);

            if (LoginResponse.Status == 0)
            {
                System.Web.Security.FormsAuthentication.RedirectFromLoginPage(LoginResponse.Token.UserName, true);
                LifetimeToken token = LoginResponse.Token;
                Session["Token"] = token;

                GetUserRequest request = new GetUserRequest() { Token = token };
                GetUserResponse response = Client.GetUser(request);

                if (response.GetUser.Type == AdOmniService.UserType.Seller)
                {
                    Response.Redirect("~/Pages/Seller/SellerHomeDashboard.aspx");
                }

                if (response.GetUser.Type == AdOmniService.UserType.Client)
                {
                    Response.Redirect("~/Pages/Buyer/BuyerHomeDashboard.aspx");
                }

                if (response.GetUser.Type == AdOmniService.UserType.None)
                {
                    Response.Redirect("~/Pages/Buyer/BuyerHomeDashboard.aspx");
                }
            }
            else
            {
                Response.Redirect("~/Login.aspx");
                Response.Write(LoginResponse.Error.ErrorMessage);
            }
        }
    }
}

我已将整个 .cs 页面内容放入 Edit 中。

4

2 回答 2

1

使用 Fiddler(一个 http 调试代理)

这将允许您在向 Web 服务发出的请求中达到峰值(以 xml 格式)

所以你可以看看你是否遗漏了什么。

通过 fiddler 引导您的 c# 客户端,并查看

http://www.fiddler2.com/fiddler2/

于 2012-12-13T10:54:10.490 回答
0

也许在您的 PHP 脚本中,您还应该设置EventNotificationURL变量。

查看错误响应中的此部分:

  ["EventNotificationUri"]=>
  NULL

也许服务希望您传递一个EventNotificationUri值,就像您传递Password,Username和一样LifetimeRequest

[编辑]

尝试将您的变量名从 更改UsernameUserName。据我所知,PHP 在这件事上应该区分大小写,所以"Username" != "UserName"

于 2012-12-13T11:25:18.267 回答