Open pauldraper opened 6 years ago
I made an example at https://github.com/ReeganExE/node-soap-example/blob/master/src/index.ts
npm run wsdl -- 'http://ws.cdyne.com/ip2geo/ip2geo.asmx?wsdl'
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]>;
}
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();
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.