Sending an API CAll with PayPal SOAP API
Asked Answered
J

1

5

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)?

Jessiajessica answered 19/1, 2010 at 21:26 Comment(1)
Can you please help me with this problem ??!?! #8763203Oblation
J
9

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);
}
Jobye answered 19/1, 2010 at 21:52 Comment(10)
Yea I had the service, just did not understand what object to use to send the request. So I know how to use the proxy classes just if I am to use like HttpWebRequest or use the proxy class instead to make the request and include the SOAPJessiajessica
I modified now the original post. Read again.Jessiajessica
HttpWebRequest is a low-level API. It is used for manually forging HTTP requests and receiving response. SOAP is a XML based protocol over HTTP. When you generate a client proxy class it will take care of properly forming the XML requests and parsing the XML responses of the server. All you need to do is to call the corresponding C# methods. So you should never use HttpWebRequest for invoking SOAP based web services but you should instead use the generated classes.Jobye
so all you have to do is call the proxy methods and that's it? Wow. Ok I'm late to the game with web services. Last time I did it via NVP and did all the code for HttpWebRequest myself: formatted XML manually with a stringbuilder, got the response via HttpWebResonse or whatever...Jessiajessica
So what's your PayPalAPIInterfaceClient? I don't see that in the latest WSDL. And I thought AbstractRequestType is what you would use. NO idea what that's for then.Jessiajessica
PayPalAPIInterfaceClient was automatically generated class when I imported the service reference from the WSDL url. It contains all the functions needed interact with the SOAP API.Jobye
Same goes for the Credentials proxy object. I don't see that in the latest wsdlJessiajessica
So why not use the [nameofMethod]RequestType and [nameofMethod]ResponseType instead?Jessiajessica
I think you must have used the API at an older date. There is no longer a AddressVerify method and I see no reason to use an instance of PayPalAPIInterfaceClient just to send a request. Looks like there is now some new methods AddressVerifyRequest and AddressVerifyResponse. I wonder why you have an instance of PayPalAPIInterfaceClient in all this.Jessiajessica
How do you know that the Client is going to send the Http Request?Jessiajessica

© 2022 - 2024 — McMap. All rights reserved.