Latest 0.9.0
Homepage https://github.com/banjun/WSDL2Swift
License MIT
Platforms ios 9.0, osx 10.11
Dependencies AEXML, BrightFutures, ISO8601, Fuzi
Authors

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)

Latest podspec

{
    "name": "WSDL2Swift",
    "version": "0.9.0",
    "summary": "Swift alternative to WSDL2ObjC making a SOAP request & parsing its response as defined in WSDL",
    "description": "Swift alternative to WSDL2ObjC making a SOAP request & parsing its response as defined in WSDL.ngenerate WSDL+(ServiceName).swift SOAP client by executing WSDL2Swift with WSDL and XSD xml files.",
    "homepage": "https://github.com/banjun/WSDL2Swift",
    "license": "MIT",
    "authors": {
        "BAN Jun": "[email protected]"
    },
    "social_media_url": "https://twitter.com/banjun",
    "platforms": {
        "ios": "9.0",
        "osx": "10.11"
    },
    "source": {
        "git": "https://github.com/banjun/WSDL2Swift.git",
        "tag": "0.9.0"
    },
    "source_files": "WSDL2Swift.swift",
    "dependencies": {
        "AEXML": [],
        "BrightFutures": [
            ">= 6.0.0-beta.1",
            "< 7.0.0"
        ],
        "ISO8601": [],
        "Fuzi": [
            "~> 2.0"
        ]
    },
    "pod_target_xcconfig": {
        "HEADER_SEARCH_PATHS": "$(SDKROOT)/usr/include/libxml2"
    }
}

Pin It on Pinterest

Share This