首页 > 解决方案 > aspx.vb 页面中的 ASP.NET VB WebMethod - 失败但在 C# 中有效

问题描述

我正在尝试将 Amazon Pay SDK 示例项目转换为 VB。编译时它在 C# 中运行得很好,但是我所做的 VB 转换失败了。我正在使用的原始 c# 项目可以在这里找到:[AmazonPay SDK 示例][1]。我正在使用 C# 对象并且仅使用 OneTimePayments 代码。

可以正常工作的 C# 代码是这样的:ASPX PAGE 调用:

$.ajax({
    type: "POST",
    url: "SetPaymentDetails.aspx/MakeApiCallAndReturnJsonResponse",
    contentType: "application/json",
    data: JSON.stringify({
         amazonOrderReferenceId: oro,
         amount: "19.95",
         addressConsentToken: access_token
    }),
    dataType: "json",
    cache: false,
    success: function (data) {
         $.each(data.d, function (key, value) {
              if (key == "getOrderReferenceDetailsResponse") {
                    $("#get_details_response").html(value);
              }
              else if (key == "setOrderReferenceDetailsResponse") {
                    $("#setOrderReferenceDetailsResponse").html(value);
              }
         });
    }
});

以及在 aspx.cs 页面中接收 c# 代码:

[WebMethod]
public static Dictionary<string, string> MakeApiCallAndReturnJsonResponse(string amazonBillingAgreementId, string amount, string addressConsentToken = "")
{
    SetOrderReferenceDetailsApiCall(amazonBillingAgreementId);
    GetOrderReferenceDetailsApiCall(amazonBillingAgreementId);
    HttpContext.Current.Session.Add("amazonBillingAgreementId", amazonBillingAgreementId);
    HttpContext.Current.Session.Add("amount", amount);
    return apiResponse;
}

VB 中的页面具有完全相同的 JavaScript。aspx.vb页面中的接收代码为:

<System.Web.Services.WebMethod()>
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)>
Public Shared Function MakeApiCallAndReturnJsonResponse(ByVal amazonBillingAgreementId As String, ByVal amount As String, ByVal addressConsentToken As String) As Dictionary(Of String, String)
    SetOrderReferenceDetailsApiCall(amazonBillingAgreementId)
    GetOrderReferenceDetailsApiCall(amazonBillingAgreementId)
    HttpContext.Current.Session.Add("amazonBillingAgreementId", amazonBillingAgreementId)
    HttpContext.Current.Session.Add("amount", amount)
    Return apiResponse
End Function

运行VB版,对WebMethod进行AJAX调用时,返回的错误是:

无效的 Web 服务调用,缺少参数值:“amazonBillingAgreementId”。在 System.Web.Script.Services.WebServiceMethodData.CallMethod(对象目标,IDictionary 2 parameters) at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary2 rawParams) 在 System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext 上下文,WebServiceMethodData methodData)

我已经坚持了一天,最后决定看看这里是否有人可以提供帮助。

先感谢您。[1]:https ://amzn.github.io/amazon-pay-sdk-samples/login_and_pay/lpa-login.html

标签: c#asp.netvb.net

解决方案


推荐阅读