我在我的 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 中。