Pos*_*Guy 5 c# paypal paypal-soap
好的,所以我的.NET项目中有服务引用.是的,我知道您现在可以访问代理类.
但是在过去,我习惯通过使用NVP的HttpWebRequest对象来做这件事,但从未尝试过使用WSDL并以这种方式发送SOAP请求.
我不太确定使用哪个对象来发送请求.不知道从哪里开始.我看过这些文档,但看不到.NET和PayPal的好例子.
除了WSDL与通过NVP API和查询字符串params发送HttpWebRequest之外,我真的不明白你发送请求的方式是否有所不同.它只是在Http上,所以你不能在SOAP API上使用HttpWebRequest(使用WSDL)吗?
首先从元数据生成服务引用:右键单击项目 - >添加服务引用并指向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);
}
Run Code Online (Sandbox Code Playgroud)