c# - 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, IDictionary
2 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
解决方案
推荐阅读
- javascript - 如何在 React Navigation 中的每个选项卡更改时有条件地渲染组件?
- c++ - C++ gRPC 同步服务器中 Python gRPC 服务器 max_workers 和 maximum_concurrent_rpcs 的等效选项
- regex - 尝试使用 dart 使用正则表达式切断 Spotify 链接
- javascript - 如何在php同一页面中使用jquery变量而不提交表单
- php - 如何在 Wheezy Debian php 5.6 中安装 php5-gd
- javascript - 将数组数组导出到 CSV
- python - 使用 MultiIndex 透视 DataFrame
- go - 如何将 go 指针作为 wasm 上下文数据传递?
- python - 使用嵌套的 For 循环和 If 条件在另一个列表中查找数字列表
- integration - 在“转换 XML”Azure 逻辑应用连接器中选择地图时出错