c# - C# WinForm Paypal 与 asmx web 服务集成时出错

标签 c# winforms web-services paypal

我正在尝试将 Paypal 支付集成到 .NET 4.0 C# WinForm 应用程序中,执行 DirectPayment(无需打开带有 paypal 站点的浏览器)通过 asmx web 服务从 WebMethod 调用此方法

public DoDirectPaymentResponseType DoDirectPaymentAPIOperation(string 
    amountinUSDollar, string creditCardType, string creditCardNumber, int 
    exp_month, int exp_year, string firstName, string middleName, string 
    lastName, string address1, string address2, string city, string state, 
    string zip, string phoneNumber, string CVV2)
{
    DoDirectPaymentResponseType response = new 
    DoDirectPaymentResponseType();
    DoDirectPaymentReq wrapper = new DoDirectPaymentReq();
    DoDirectPaymentRequestType request = new DoDirectPaymentRequestType();
    DoDirectPaymentRequestDetailsType requestDetails = new 
        DoDirectPaymentRequestDetailsType();
    requestDetails.PaymentAction = (PaymentActionCodeType)               
        Enum.Parse(typeof(PaymentActionCodeType), "SALE");
    CreditCardDetailsType creditCard = new CreditCardDetailsType();
    PayerInfoType cardOwner = new PayerInfoType();
    PersonNameType payer = new PersonNameType();
    payer.FirstName = firstName;
    payer.MiddleName = middleName;
    payer.LastName = lastName;
    cardOwner.PayerName = payer;
    creditCard.CardOwner = cardOwner;
    creditCard.CreditCardNumber = creditCardNumber; 
    if (creditCardType == "VISA")
    {
        creditCard.CreditCardType = CreditCardTypeType.VISA;
    }
    else if (creditCardType == "MasterCard")
    {
        creditCard.CreditCardType = CreditCardTypeType.MASTERCARD;
    }
    creditCard.CVV2 = CVV2;
    creditCard.ExpMonth = exp_month;
    creditCard.ExpYear = exp_year;
    requestDetails.PaymentDetails = new PaymentDetailsType();
    requestDetails.PaymentDetails.NotifyURL = "http://IPNhost";
    BasicAmountType paymentAmount = new 
        BasicAmountType(CurrencyCodeType.USD, amountinUSDollar);
    requestDetails.PaymentDetails.OrderTotal = paymentAmount;
    wrapper.DoDirectPaymentRequest = request;
    Dictionary<string, string> config = getConfigDict();
    PayPalAPIInterfaceServiceService service = new 
        PayPalAPIInterfaceServiceService(config);
    response = service.DoDirectPayment(wrapper);
}

当它尝试调用 API 时,在代码的最后一行出现此错误: “HttpConnection Execute 中的异常:无效的 HTTP 响应请求被中止:无法创建 SSL/TLS 安全通道。”} System.Exception {PayPal.Exception.PayPalException}。

我有一个集成了 Paypal 的 .NET 4.5 WebForm Web 应用程序,我必须在其中定义它

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

在其 Global.asax 文件中,它解决了该特定应用程序的问题,我发现我必须使用它

ServicePointManager.SecurityProtocol = (SecurityProtocolType) 3072; 

对于 .NET 4.0 但我的问题是:

如果这将是可能问题的解决方案,我应该将此行放在我的代码中的什么位置?因为我的 asmx 网络服务中没有 Global.asax。

最佳答案

根据 OP 中的评论概述上述报告问题的来源。抛出异常是因为 NotifyURL 不在 https 中。

关于c# - C# WinForm Paypal 与 asmx web 服务集成时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46181111/

相关文章:

c# - 在 Windows 启动时运行 C# 应用程序

c# - 用自定义图像替换 "red-cross"的DataGridViewImageColumn中的 "new-row"

c# - 如何在不超出范围的情况下从列表中删除多个条目?

c# - 将方法分配给动态创建的控件

c# - 启动多个 gui (WinForms) 线程以便它们可以与 C# 中的一个主 gui 分开工作?

c# - 为什么 DwmGetWindowAttribute 与 DWMWA_EXTENDED_FRAME_BOUNDS 在切换监视器时表现异常?

python - 如何从iOS应用程序调用Python的ladon框架开发的Web服务?

php - 使用仅提供用户名、密码和证书颁发机构的 PHP 连接到 Web 服务

java - 带有可选键的Web服务,带有 Camel 的值映射?

c# - Asp.Net 路由 - 显示完整的 URL