Monday, 15 June 2015

ios - consuming web service from iphone error -



ios - consuming web service from iphone error -

i've been next tutorial http://iphonebyradix.blogspot.ca/2011/04/working-with-webservices.html , decided create own web service using xaramin , seek phone call it. seems doesn't called reason.

service1.asmx [webmethod] public string printsomething(string userdata){ console.writeline("test"); console.out.writeline(); homecoming userdata; } post /service1.asmx soapaction: http://tempuri.org/printsomething content-type: text/xml; charset=utf-8 content-length: string host: string <?xml version="1.0" encoding="utf-16"?> <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> <printsomething xmlns="http://tempuri.org/"> <userdata>string</userdata> </printsomething> </soap:body> </soap:envelope> http/1.0 200 ok content-type: text/xml; charset=utf-8 content-length: string <?xml version="1.0" encoding="utf-16"?> <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> <printsomethingresponse xmlns="http://tempuri.org/"> <printsomethingresult>string</printsomethingresult> </printsomethingresponse> </soap:body> </soap:envelope>

viewcontroller.h

(ibaction)invoke:(id)sender { nsstring *soapformat =[nsstring stringwithformat:@"<?xml version=\"1.0\" encoding=\"utf-16\"?>\n" "<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/\">\n" "<soap:body>\n" "<printsomething xmlns=\"http://tempuri.org/\">\n" "<userdata>12</userdata>" "</printsomething>\n" "</soap:body>\n" "</soap:envelope>\n"]; nslog(@"the request format %@",soapformat); //location of web method nsurl *locationofwebservice = [nsurl urlwithstring:@"http://tempuri.org/printsomething/service1.asmx"]; nslog(@"web url = %@",locationofwebservice); //create connection request nsmutableurlrequest *therequest = [[nsmutableurlrequest alloc]initwithurl:locationofwebservice]; nsstring *msglength = [nsstring stringwithformat:@"%d",[soapformat length]]; [therequest addvalue:@"text/xml; charset=utf-8" forhttpheaderfield:@"content-type"]; [therequest addvalue:@"http://tempuri.org/printsomething" forhttpheaderfield:@"soapaction"]; [therequest addvalue:msglength forhttpheaderfield:@"content-length"]; [therequest sethttpmethod:@"post"]; //the below encoding used send info on net [therequest sethttpbody:[soapformat datausingencoding:nsutf8stringencoding]]; //check if connection established or not nsurlconnection *connect = [[nsurlconnection alloc]initwithrequest:therequest delegate:self]; } -(void)connection:(nsurlconnection *)connection didreceiveresponse:(nsurlresponse *)response { [webdata setlength: 0]; } -(void)connection:(nsurlconnection *)connection didreceivedata:(nsdata *)data { [webdata appenddata:data]; } -(void)connection:(nsurlconnection *)connection didfailwitherror:(nserror *)error { nslog(@"error theconenction"); //[connection release]; //[webdata release]; } -(void)connectiondidfinishloading:(nsurlconnection *)connection { nslog(@"done. received bytes: %d", [webdata length]); nsstring *thexml = [[nsstring alloc] initwithbytes: [webdata mutablebytes] length:[webdata length] encoding:nsutf8stringencoding]; //nsstring *thexml = [[nsstring alloc] initwithbytes: [webdata mutablebytes] length:[webdata length] encoding:nsutf16stringencoding]; nslog(@"%@",thexml); //[thexml release] } //recieving xml server - (void)parser:(nsxmlparser *)parser didstartelement:(nsstring *)elementname namespaceuri:(nsstring *)namespaceuri qualifiedname:(nsstring *)qualifiedname attributes:(nsdictionary *)attributedict { nslog(@"didstart"); if([elementname isequaltostring:@"printsomethingresult"]){ // if(!soapresults) nslog(@"innnnn"); } } - (void)parser:(nsxmlparser *)parser foundcharacters:(nsstring *)string { nslog(@"foundcharacter"); [nodecontent appendstring:[string stringbytrimmingcharactersinset:[nscharacterset whitespaceandnewlinecharacterset]]]; } - (void)parser:(nsxmlparser *)parser didendelement:(nsstring *)elementname namespaceuri:(nsstring *)namespaceuri qualifiedname:(nsstring *)qname { nslog(@"didendelement %@",nodecontent); //if ([elementname isequaltostring:@"celsiustofahrenheitresult"]) { if ([elementname isequaltostring:@"printsomethingresult"]) { finaldata = nodecontent; //output.text = finaldata; nslog(@"final info ===================== %@",finaldata); } //output.text = finaldata; }

it says message got sent web service not receiving though

2014-06-23 09:22:31.814 soapservicetest[3638:60b] request format <?xml version="1.0" encoding="utf-16"?> <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> <printsomething xmlns="http://tempuri.org/"> <userdata>12</userdata></printsomething> </soap:body> </soap:envelope> 2014-06-23 09:22:31.817 soapservicetest[3638:60b] web url = http://tempuri.org/printsomething/service1.asmx 2014-06-23 09:22:32.436 soapservicetest[3638:60b] done. received bytes: 44115 2014-06-23 09:22:32.438 soapservicetest[3638:60b] <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"><html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"><head><meta content="text/html; charset=utf-8" http-equiv="content-type" /><script type="text/javascript">//<![cdata[ si_st=new date //]]></script><script type="text/javascript">//<![cdata[ sb_gh=function(){return location.hash},sb_sh=function(n){location.hash=n};function _ge(n){return _d.getelementbyid(n)}_w=window,_d=document,sb_de=_d.documentelement,sb_ie=!!_w.activexobject,sb_i6=sb_ie&&!_w.xmlhttprequest,sb_st=_w.settimeout,sb_ct=_w.cleartimeout,sb_gt=function(){return+new date};sj_evt=new function(){function i(n){return t[n]||(t[n]=[])}var t={},n=this;n.fire=function(n){for(var r=i(n),u=r.e=arguments,t=0;t<r.length;t++)r[t].d?sb_st(sj_wf(r[t],u),r[t].d):r[t](u)},n.bind=function(n,t,r,u){var f=i(n);t.d=u,f.push(t),r&&f.e&&t(f.e)},n.unbind=function(n,i){for(var u=0,r=t[n];r&&u<r.length;u++)if(r[u]==i){r.splice(u,1);break}}};_g={st:(si_st?si_st:new date),mkt:"en-ca",rtl:false,ver:"9_00_0_3007771",ig:"8b539654167049fb97e266c2dce07427",eventid:"acb9ce0d1a43492083fd2e73c90b66f9",v:"homepage",p:"serp",da:"nycr2v2",cid:"2cb5dc5900ce647e2293da0601df640f",suih:"ta00bzwuo-pij79cvdkbva",pcid:"1",curl:"http:\/\/c.bing.com\/c.gif?di=15074",akamaisyncurl:"http:\/\/cms.abmr.net\/pix?cid=1

i played around encoding since soap message charset utf 8 , encoding 16 did seem work either

you receiving response server, made plain log:

received bytes: 44115

so, issue on server. replies, request not routed right page, wrong page 1 replies.

inspect content of thexml understand page replying, maybe sort of 404-page or alike.

ios web-services

No comments:

Post a Comment