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= \"http://www.w3.org/2001/XMLSchema-instance \ "xmlns:xsd= \" Http://www.w3.org/2001/XMLSchema \ "Xmlns:soap = \" http ://schemas.xmlsoap.org/soap/envelope/\ "> \<soap:Body> <xiaoxi xmlns= \"http://tempuri.org/\ "> \<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://tempuri.org/UserLogin"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:@"http://tempuri.org/%@", 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