Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support *Async methods for soap client #11

Open
pauldraper opened this issue Nov 10, 2018 · 1 comment
Open

Support *Async methods for soap client #11

pauldraper opened this issue Nov 10, 2018 · 1 comment

Comments

@pauldraper
Copy link

pauldraper commented Nov 10, 2018

The soap library adds methods that return a promise. By default this are suffixed with Async, though that is customizable (in case it conflicts with a method).

E.g.

await output = client.LaunchTheMisslesAsync(input);
@ReeganExE
Copy link

I made an example at https://github.com/ReeganExE/node-soap-example/blob/master/src/index.ts

Generate types

npm run wsdl -- 'http://ws.cdyne.com/ip2geo/ip2geo.asmx?wsdl'
Output at src/IP2Geo/IP2GeoSoap.d.ts

will look like this:

export interface IIP2GeoSoapSoap extends Client {
    ResolveIP: (input: Partial<IResolveIPInput>, cb: (err: any | null, result: IResolveIPOutput, rawResult: string,  soapHeader: {[k: string]: any; },  rawRequest: string) => any, options?: any, extraHeaders?: any) => void;
    ResolveIPAsync: (input: Partial<IResolveIPInput>, options?: any, extraHeaders?: any) => Promise<[IResolveIPOutput, string, {[k: string]: any; }, string]>;
}

Test the output

import { createClientAsync, Client } from 'soap';
// import types from the generated source
import { IIP2GeoSoapSoap } from './IP2Geo/IP2GeoSoap';

function createSoapClientAs<T extends Client>(url: string): Promise<T> {
  return createClientAsync(url) as Promise<T>;
}

async function main() {
  const url = 'http://ws.cdyne.com/ip2geo/ip2geo.asmx?wsdl';
  const client = await createSoapClientAs<IIP2GeoSoapSoap>(url);

  try {
    const [result] = await client.ResolveIPAsync({ ipAddress: '1.1.1.1', licenseKey: '' });
    console.log(result.ResolveIPResult);
  } catch (error) {
    console.log(error);
  }
}

main();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants