我想对此Web服务示例进行请求:
感谢您的帮助。
解决方案我编写了一个pod,用于将XML映射到对象,名为 XMLMapper 。 (使用与 ObjectMapper 相同的技术)
您可以使用请求子规范轻松创建SOAP请求。 p>
首先创建自己的自定义 SOAPMessage :
类HolidayServiceMessage:SOAPMessage { var countryCode:字符串? 覆盖功能映射(map:XMLMap){ super.mapping(map:map) countryCode<-map [ m:countrycode] } }然后创建SOAPEnvelope,例如:
let soapMessage = HolidayServiceMessage(soapAction: GetHolidaysAvaible,nameSpace: holidaywebservice/HolidayService_v2) soapMessage.countryCode =美国 let soapEnvelope = SOAPEnvelope(soapMessage:soapMessage)最后使用Alamofire发送SOAP请求:
Alamofire.request( holidaywebservice/HolidayService_v2/HolidayService2.asmx ?wsdl,方法:.post,参数:soapEnvelope.toXML(),编码:XMLEncoding.soap(withAction: holidaywebservice/HolidayService_v2#GetHolidaysAvaible))您可以使用 XMLMappable 协议将XML响应映射到快速对象。
I want to do a request to this web service example: www.holidaywebservice//HolidayService_v2/HolidayService2.asmx?wsdl
I need to send one parameter "countryCode". I don't know how can i do that with alamofire. And how i get the response to parse the xml result.
This is how i did in postman, but i want to know how do the same in swift.
Thanks for your help.
解决方案I wrote a pod for mapping XML to objects, called XMLMapper. (uses the same technique as the ObjectMapper)
You can use the Requests subspec to create easily SOAP requests.
First create your own custom SOAPMessage:
class HolidayServiceMessage: SOAPMessage { var countryCode: String? override func mapping(map: XMLMap) { super.mapping(map: map) countryCode <- map["m:countrycode"] } }Then create the SOAPEnvelope like:
let soapMessage = HolidayServiceMessage(soapAction: "GetHolidaysAvaible", nameSpace: "holidaywebservice/HolidayService_v2") soapMessage.countryCode = "UnitedStates" let soapEnvelope = SOAPEnvelope(soapMessage: soapMessage)Finaly send the SOAP request using Alamofire:
Alamofire.request("holidaywebservice/HolidayService_v2/HolidayService2.asmx?wsdl", method: .post, parameters: soapEnvelope.toXML(), encoding: XMLEncoding.soap(withAction: "holidaywebservice/HolidayService_v2#GetHolidaysAvaible"))You can map the XML response to swift objects using XMLMappable protocol.
更多推荐
带有Alamofire的Swift 2.0 Soap请求发送xml参数
发布评论