Ok Paypal 让我发疯。我直接从 xcom 的最新区域(或者他们现在所说的任何东西)获取了他们的“示例代码”,并安装了 DLL 就好了。我正在做一个简单的 TransactionSearch,如下所示:
protected void btnSearch_Click(object sender, EventArgs e)
{
GenerateCodeSOAP.TransactionSearch t = new GenerateCodeSOAP.TransactionSearch();
String mysearch = t.TransactionSearchnCode(Convert.ToDateTime(dtStart.Text), Convert.ToDateTime(dtEnd.Text), "05S08011830926906");
Response.Write("Results:<br/>" + mysearch);
lblStatus.Text = "Finished";
}
这是我用我自己的 API 内容稍微修改的示例代码:
public class TransactionSearch
{
public TransactionSearch()
{
}
public string TransactionSearchnCode(DateTime startDate, DateTime endDate,string transactionId)
{
CallerServices caller = new CallerServices();
IAPIProfile profile = ProfileFactory.createSignatureAPIProfile();
// Set up your API credentials, PayPal end point, and API version.
profile.APIUsername = "[removed for security]";
profile.APIPassword = "[removed for security]";
profile.APISignature = "[removed for security]";
profile.Subject = "[removed for security]";
profile.Environment = "live";
// Create the request object.
TransactionSearchRequestType concreteRequest = new TransactionSearchRequestType();
concreteRequest.Version="92.0";
// Add request-specific fields to the request.
concreteRequest.StartDate = startDate;
concreteRequest.EndDate = endDate.AddHours(23).AddMinutes(59).AddSeconds(59);
concreteRequest.EndDateSpecified = true;
//concreteRequest.TransactionID=transactionId;
// Execute the API operation and obtain the response.
TransactionSearchResponseType pp_response=new TransactionSearchResponseType();
pp_response= (TransactionSearchResponseType) caller.Call("TransactionSearch", concreteRequest);
return pp_response.Ack.ToString();
}
}
无论我尝试什么(你会看到我注释掉了 transactionid 只是为了给我一些东西)我在这一行得到一个 Object Reference Not Set 错误:
pp_response= (TransactionSearchResponseType) caller.Call("TransactionSearch", concreteRequest);
我知道这只是“示例代码”,但这似乎应该很简单。我通过沙箱尝试过,但显然没有用,所以我在自己的贝宝账户中有交易,所以我设置了 API 凭据,但它仍然无法正常工作。