Skip to content
Pure Swift alternative to WSDL2ObjC making a SOAP request & parsing its response as defined in WSDL
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
WSDL2Swift.xcodeproj bundle update & pod update Jun 29, 2018
WSDL2Swift.xcworkspace
WSDL2Swift
fastlane remove generic destination specifier from macOS target Jun 29, 2018
iOSWSDL2Swift add sample tempconvert wsdl to version control to use in CI without m… Jun 29, 2018
iOSWSDL2SwiftTests make soapRequest public to omit `@testable import`. Dec 20, 2016
.gitignore add fastlane test lane Jun 29, 2018
.swift-version
Gemfile
Gemfile.lock
LICENSE initial commit Nov 22, 2016
Podfile
Podfile.lock bundle update & pod update Jun 29, 2018
README.md Update readme Mar 19, 2019
WSDL2Swift.podspec
WSDL2Swift.swift Fixed wrong code. Mar 19, 2019

README.md

WSDL2Swift

Build Status Version License Platform

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

Input

  • WSDL 1.1 xmls
  • XSD xmls

Output

  • a Swift file which works as SOAP client
    • Swift 4 (Xcode 9)
    • NSURLSession for connection
    • BrightFutures for returning asynchronous requests
    • Fuzi for fast parsing xmls
    • AEXML for generating xmls

Usage

Build

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

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.

Use In App

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.

Customize

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.

Example

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.

Architecture

usage point of view...

  • initialize Service with endpoint URL (endpoint URL can be changed after generating WSDL+(ServiceName).swift)
  • initialize request parameter with ServiceName_OperationName(...)
  • Service.request(param) to get Future that will be completed by NSURLSession completion
  • parameters and models are typed by xsd definition (even with nullability)
You can’t perform that action at this time.