【发布时间】:2012-07-23 22:26:01
【问题描述】:
好吧,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);
我知道这只是“示例代码”,但这看起来应该很简单。我通过沙盒尝试过,但显然没有用,所以我在自己的 paypal 帐户中有交易,所以我设置了 API 凭据,但它仍然无法正常工作。
【问题讨论】:
-
很久没有做过 Paypal,所以这更笼统 - 调试并在行中放置一个断点 - 如果实际发出请求(或与请求阻止它发生)。
-
EdSF,你成功了,但我不确定如何将你的标记为答案。我认为您需要正式回答。这里的关键是调试提示。 Paypal 的示例代码完全省略了将 APIProfile 分配给调用者对象。看着调试(我应该马上有....)它对我来说就像一个酸痛的拇指。再次感谢!!!
-
酷...刚刚...谢谢