Swift alternative to WSDL2ObjC making a SOAP request & parsing its response as defined in WSDL. Objective-C free.
Stubs for unit test can be implemented using Toki.
Input
Output
bundle install
bundle exec fastlane archive
you can build and debug with WSDL2Swift scheme of the xcodeproj. Archive build is not supported yet.
product executable is portable, as long as shipped with ./Frameworks and ./Stencils.
generate WSDL.swift from WSDL and XSD xmls:
./build/Build/Products/Release/WSDL2Swift --out path/to/WSDL.swift path/to/service.wsdl.xml path/to/service.xsd.xml
the order of input files is important. referenced XSDs should be placed immediately after referencing WSDL.
add WSDL.swift to your project and use: (note that service type name and requeest type name are vary, depending on source WSDL)
generated code from example by w3schools temperature converter:
public struct TempConvert: WSDLService {
:
public func request(_ parameters: TempConvert_CelsiusToFahrenheit) -> Future<TempConvert_CelsiusToFahrenheitResponse, WSDLOperationError> {
return requestGeneric(parameters)
}
:
}
:
public struct TempConvert_CelsiusToFahrenheit {
public var Celsius: String?
}
public struct TempConvert_CelsiusToFahrenheitResponse {
public var CelsiusToFahrenheitResult: String?
}
:
(continued...)
code using the generated client:
let service = TempConvert(endpoint: "http://www.w3schools.com")
service.request(TempConvert_CelsiusToFahrenheit(Celsius: "23.4")).onComplete { r in
NSLog("%@", "TempConvert_CelsiusToFahrenheit(Celsius: \"23.4\") = \(r)")
}
with dependencies:
pod 'WSDL2Swift'
note that pod WSDL2Swift just introduces runtime dependencies. it does not provide WSDL2Swift executable binary nor generated WSDL client Swift files.
sometimes, somewhere in your dependencies chain (transitive framework dependencies or test bundle), header search paths for libxml2 is required. see podspec to add manually.
You can specify charset of SOAP request by editing the generated code.
The following code is an example when you want to specify character code to be interpreted as utf-8.
public var characterSetInContentType: CharacterSetInContentType {
return .utf8
}
By default, unspecified
is set.
iOSWSDL2Swift target in xcodeproj is an example using WSDL2Swift.
it generates WSDL+(ServiceName).swift
at the first step of build and use it from ViewController.swift.
you need to place your WSDL and XSD xmls into exampleWSDLS folder.
usage point of view...
WSDL+(ServiceName).swift
)ServiceName_OperationName(...)
Service.request(param)
to get Future
that will be completed by NSURLSession
completion