ios--Docking SOAP Protocol interface

Source: Internet
Author: User
Tags soap

Recently in the docking SOAP protocol interface, respectively, using AFN and the system's own method for parsing. SOAP protocol specifically what is not elaborated, can be self-Baidu.

Say something you need to be aware of:

1,ios with the SOAP protocol interface, parameters to pass the XML format of the string, the specific format to see the interface description, it is important to maintain consistency;

2,soap1.1 and soap1.2 Use the same idea is the same, but set the parameters are not the same, the specific look at the code;

The return value of the 3,SOAP protocol is also in XML format, need to parse the XML, get the data under the node (it is emphasized that we can get the required data according to a node, but also can get the required data directly through the root node regardless of the XML node, this is how to return the background).

First look at the parameter format to be passed: it's just a request body, just an XML format.

NSString *soapmessage =[NSString stringWithFormat:@"<?xml version= \"1.0\"encoding=\ "utf-8\"?> \<soap:envelope xmlns:xsi= \" \ "xmlns:xsd= \" Http:// \ "Xmlns:soap = \" http ://\ "> \<soap:Body>                          <xiaoxi xmlns= \"\ "> \<typeValue>%@</typeValue>                         </xiaoxi>                          </soap:Body>                          </soap:Envelope>",@"147"];

The system comes with the method to parse:

#pragmaMark-With the system comes with-(void) Postwithsoapmessage: (NSString *) Message {//URLNsurl *url =[Nsurl urlwithstring:xmhttpaddress]; //RequestNsmutableurlrequest *request =[Nsmutableurlrequest Requestwithurl:url]; //set the POST request method[Request Sethttpmethod:@"POST"]; //SOAPAction soap1.1 must be set soap1.2 not set[Request AddValue:@"Http://"Forhttpheaderfield:@"SOAPAction"]; /** Content-type * soap1.1 text/xml; Charset=utf-8 * soap1.2 application/soap+xml; Charset=utf-8*/[Request AddValue:@"text/xml; Charset=utf-8"Forhttpheaderfield:@"Content-type"]; //number of request bytes[Request Addvalue:[nsstring stringWithFormat:@"%zd", Message.length] Forhttpheaderfield:@"Content-length"]; //set the request Body UTF-8 encoding[Request Sethttpbody:[message datausingencoding:nsutf8stringencoding]; //SessionNsurlsession *session =[Nsurlsession sharedsession]; //TaskNsurlsessiondatatask *task = [Session datataskwithrequest:request completionhandler:^ (NSData * _Nullable data, Nsurlresponse * _nullable response, Nserror *_nullable Error) {        //ResultsNSString *result =[[NSString alloc] Initwithdata:data encoding:nsutf8stringencoding]; Xmlog (@"result =%@", result);    }]; [Task resume];}

Use AFN to parse

//POST request here a little encapsulation, easy to use, see the main can ....- (void) Postwithsoapaction: (NSString *) Action Parameters: (NSString *) SoapMessage success: (Success) Success failure: (failure) Failure {Afnmanager.responseserializer=[Afhttpresponseserializer Serializer]; Afnmanager.requestserializer=[Afhttprequestserializer Serializer]; /** General AFN request parameters can only be translated into a dictionary * but in this method the request parameter is converted into a string form*/[Afnmanager.requestserializer setquerystringserializationwithblock:^nsstring * _nonnull (nsurlrequest * _nonnull request,ID_nonnull parameters, Nserror * _nullable __autoreleasing *_nullable Error) {                returnSoapMessage;    }]; //Request Settings[Afnmanager.requestserializer SetValue:@"text/xml; Charset=utf-8"Forhttpheaderfield:@"Content-type"]; [Afnmanager.requestserializer setvalue:[nsstring stringWithFormat:@"%zd", Soapmessage.length] Forhttpheaderfield:@"Content-length"]; [Afnmanager.requestserializer setvalue:[nsstring stringWithFormat:@"", Action] Forhttpheaderfield:@"SOAPAction"]; //POST Request[Afnmanager post:xmhttpaddress parameters:soapmessage progress:nil success:^ (nsurlsessiondatatask * _Nonnull task,ID_nullable Responseobject)        {[Svprogresshud dismiss]; if(responseobject) {NSString*response =[self getjsonstringwithdata:responseobject];        Success (response); }Else{Xmlog (@"%@",@"request failed"); }} failure:^ (Nsurlsessiondatatask * _nullable task, Nserror *_nonnull Error)    {failure (error); }];}

I stepped on a lot of pits, but it was done ...

ios--Docking SOAP Protocol interface

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.