好的,我的 .NET 项目中有服务引用。是的,我知道您现在可以访问代理类。

但在过去,我习惯于使用 NVP 通过 HttpWebRequest 对象执行此操作,但从未尝试过使用 WSDL 并以这种方式发送 SOAP 请求。

我不太确定使用哪个对象来发送请求。不知道从哪里开始。我查看了文档,但没有看到 .NET 和 PayPal 的好的示例。

除了 WSDL 与 WSDL 之外通过 NVP API 和查询字符串参数发送 HttpWebRequest,我真的不明白发送请求的方式是否有差异。这一切都通过 Http 进行,所以您不能通过 SOAP API(使用 WSDL)使用 HttpWebRequest 吗?

有帮助吗?

解决方案

首先从元数据生成服务引用:右键单击项目 -> 添加服务引用并指向 WSDL url: https://www.sandbox.paypal.com/wsdl/PayPalSvc.wsdl

这将为当前项目生成可用于发送请求的代理类:

using (var client = new PayPalAPIInterfaceClient())
{
    var credentials = new CustomSecurityHeaderType
    {
        Credentials = new UserIdPasswordType
        {
            Username = "username",
            Password = "password"
        }
    };
    var request = new AddressVerifyReq
    {
        AddressVerifyRequest = new AddressVerifyRequestType
        {
            Street = "some street",
            Zip = "12345"
        }
    };
    var response = client.AddressVerify(ref credentials, request);
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top