我过去在VB.net开发过,我根本无法弄清楚如何正确调用此函数以及如何获取响应,以便我可以在网页响应中显示它。
我将示例c#代码翻译成VB。这是我的aspx页面的代码,我希望用它来发出请求,然后在我的页面中显示响应:
Imports OffAmazonPaymentsService
Imports OffAmazonPaymentsService.Model
Public Class WebForm1
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Write(GetOrderReferenceDetails(???service???, "asdfsadf", "asdfsadf", "asdfasdf"))
End Sub
Private Shared Function GetOrderReferenceDetails(service As IOffAmazonPaymentsService, sellerId As String, amazonOrderReferenceId As String, addressConsentToken As String) As GetOrderReferenceDetailsResponse
' Required parameters
Dim request As New GetOrderReferenceDetailsRequest()
request.SellerId = sellerId
request.AmazonOrderReferenceId = amazonOrderReferenceId
' Optional parameters
request.AddressConsentToken = addressConsentToken
Return service.GetOrderReferenceDetails(request)
End Function
End Class
我不知道如何调用该函数的第一个(服务)参数,然后显示响应的内容。
如果我的问题不够明确,请告诉我。 这是他们用尖锐格式给出的例子......
using OffAmazonPaymentsService;
using OffAmazonPaymentsService.Model;
public class GetOrderReferenceDetailsSample
{
/**
* Sample GetOrderReferenceDetails method that takes generic inputs, constructs a request object,
* and make a call to the service.
*/
private static GetOrderReferenceDetailsResponse GetOrderReferenceDetails(
IOffAmazonPaymentsService service,
string sellerId,
string amazonOrderReferenceId,
string addressConsentToken)
{
// Required parameters
GetOrderReferenceDetailsRequest request = new GetOrderReferenceDetailsRequest();
request.SellerId = sellerId;
request.AmazonOrderReferenceId = amazonOrderReferenceId;
// Optional parameters
request.AddressConsentToken = addressConsentToken;
return service.GetOrderReferenceDetails(request);
}
}
答案 0 :(得分:0)
免责声明:我的VB“生锈”,因此需要调试和改进
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim props As OffAmazonPaymentsServicePropertyCollection = OffAmazonPaymentsServicePropertyCollection.getInstance()
Dim client As New OffAmazonPaymentsServiceClient(props)
Dim result as GetOrderReferenceDetailsResponse = GetAmzOrderRef(client, props, "oref", "token")
End Sub
Private Shared Function GetAmzOrderRef(service As IOffAmazonPaymentsService, props As OffAmazonPaymentsServicePropertyCollection, amazonOrderReferenceId As String, addressConsentToken As String) As GetOrderReferenceDetailsResponse
Dim request as New GetOrderReferenceDetailsRequest()
With request
.SellerId = props.MerchantID
.AmazonOrderReferenceId = amazonOrderReferenceId
.AddressConsentToken = addressConsentToken
End With
Return service.GetOrderReferenceDetails(request)
End Function
注意:
您应该拥有config
values set(必要时为web.config
或app.config
),OffAmazonPaymentsServicePropertyCollection.getInstance()
将获得价值
由于引用标识和令牌的虚拟值,上述示例代码将失败(如预期的那样),但“错误”来自Amazon API(已经) - 例如响应错误“无效引用ID”或“无效令牌”等....
H个....