问题描述
我想对此Web服务示例进行请求:
感谢您的帮助。
我编写了一个pod,用于将XML映射到对象,名为 。 (使用与相同的技术)
您可以使用子规范轻松创建SOAP请求。 p>
首先创建自己的自定义 SOAPMessage
:
类HolidayServiceMessage:SOAPMessage {
var countryCode:字符串?
覆盖功能映射(map:XMLMap){
super.mapping(map:map)
countryCode<-map [ m:countrycode]
}
}
然后创建SOAPEnvelope,例如:
let soapMessage = HolidayServiceMessage(soapAction: GetHolidaysAvaible,nameSpace: http://holidaywebservice.com/HolidayService_v2)
soapMessage.countryCode =美国
let soapEnvelope = SOAPEnvelope(soapMessage:soapMessage)
最后使用Alamofire发送SOAP请求:
Alamofire.request( http://holidaywebservice.com/HolidayService_v2/HolidayService2.asmx ?wsdl,方法:.post,参数:soapEnvelope.toXML(),编码:XMLEncoding.soap(withAction: http://holidaywebservice.com/HolidayService_v2#GetHolidaysAvaible))
您可以使用 XMLMappable
协议将XML响应映射到快速对象。
I want to do a request to this web service example: http://www.holidaywebservice.com//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: "http://holidaywebservice.com/HolidayService_v2")
soapMessage.countryCode = "UnitedStates"
let soapEnvelope = SOAPEnvelope(soapMessage: soapMessage)
Finaly send the SOAP request using Alamofire:
Alamofire.request("http://holidaywebservice.com/HolidayService_v2/HolidayService2.asmx?wsdl", method: .post, parameters: soapEnvelope.toXML(), encoding: XMLEncoding.soap(withAction: "http://holidaywebservice.com/HolidayService_v2#GetHolidaysAvaible"))
You can map the XML response to swift objects using XMLMappable
protocol.
这篇关于带有Alamofire的Swift 2.0 Soap请求发送xml参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!