我使用 node-soap 和 soap-decorators 与 Quickbooks 进行通信。以下来自我的app.ts 文件:
this.express.use(
'/soap',
soap(this.quickbooksController, {
overrideRootElement: {
namespace: '',
xmlnsAttributes: [
{
name: 'xmlns',
value: 'http://developer.intuit.com/'
}
]
}
})
);
控制器的注释如下:
import { SoapOperation, SoapService } from 'soap-decorators';
import { AuthenticateRequest, AuthenticateResponse } from './model/authenticate.interface';
@SoapService({
portName: 'QBWebConnectorSvcSoap',
serviceName: 'QBWebConnectorSvc',
targetNamespace: 'http://developer.intuit.com/'
})
export class QuickbooksController {
@SoapOperation(AuthenticateResponse)
authenticate(data: AuthenticateRequest, res: (res: AuthenticateResponse) => any): void {
res({ authenticateResult: { string: ['', 'NVU'] } });
}
}
我的请求和响应对象被修饰为 XSD 类型:
import { XSDComplexType, XSDElement } from 'soap-decorators';
@XSDComplexType
export class AuthenticateRequest {
@XSDElement
strUserName: string;
@XSDElement
strPassword: string;
}
@XSDComplexType
class AuthenticateResult {
@XSDElement({ type: 'string' })
string: string[];
}
@XSDComplexType({ name: 'authenticateResponse' })
export class AuthenticateResponse {
@XSDElement
authenticateResult: AuthenticateResult;
}