Paypal API TransactionSearch对象参考未设置asp.net

时间:2012-07-25 13:16:19

标签: asp.net api paypal

好的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凭据,但它仍然不起作用。

1 个答案:

答案 0 :(得分:0)

多年来没有完成Paypal,所以这更通用 - 调试并在行中设置断点 - 如果请求实际发生,您应该从PayPal获得一些错误响应(或者请求的问题阻止它成为制造)。