Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending an API CAll with PayPal SOAP API

Ok, so I have the service reference in my .NET project. And yes I know that you now have access to proxy classes.

But in the past, I am used to doing this via an HttpWebRequest object using NVP, but never tried using the WSDL and sending a SOAP request this way.

I'm not quite sure which object to use to send the request. Not sure where to start here. I've looked at the docs but seen no good examples out there for .NET and PayPal.

Other than a WSDL vs. sending an HttpWebRequest via a NVP API and querystring params, I really do not understand if there's a difference in how you send the request. It's all just over Http so can't you use HttpWebRequest also over a SOAP API (using WSDL)?

like image 735
PositiveGuy Avatar asked Jan 19 '10 21:01

PositiveGuy


1 Answers

You start by generating a service reference from the metadata: Right click on the project -> Add Service Reference and point to the WSDL url: https://www.sandbox.paypal.com/wsdl/PayPalSvc.wsdl

This will generate proxy classes to the current project which could be used to send requests:

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);
}
like image 60
Darin Dimitrov Avatar answered Nov 01 '22 03:11

Darin Dimitrov