How to post and get asmx web serivce access using iPhone app?









up vote
0
down vote

favorite
1












I am new to iPhone app development. How can I post data and get data by accessing the asmx web service using iPhone app?










share|improve this question



























    up vote
    0
    down vote

    favorite
    1












    I am new to iPhone app development. How can I post data and get data by accessing the asmx web service using iPhone app?










    share|improve this question

























      up vote
      0
      down vote

      favorite
      1









      up vote
      0
      down vote

      favorite
      1






      1





      I am new to iPhone app development. How can I post data and get data by accessing the asmx web service using iPhone app?










      share|improve this question















      I am new to iPhone app development. How can I post data and get data by accessing the asmx web service using iPhone app?







      iphone web-services






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 21:02









      halfer

      14.3k758107




      14.3k758107










      asked Dec 9 '11 at 12:52









      Selwyn

      89161535




      89161535






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          I think asmx webservices are SOAP webservices you should read my blog entry here -



          http://www.makebetterthings.com/iphone/call-soap-web-service-from-iphone/



          To call a SOAP service first i create a string with the SOAP request as follows.



           NSString *soapMessage = @"<?xml version="1.0" encoding="utf-8"?>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"
          "<CelsiusToFahrenheit xmlns="http://tempuri.org/">n"
          "<Celsius>50</Celsius>n"
          "</CelsiusToFahrenheit>n"
          "</soap:Body>n"
          "</soap:Envelope>n";


          After creating the SOAP request I create a NSMutableRequest to send this request to server.

          NSURL *url = [NSURL URLWithString:@"http://w3schools.com/webservices/tempconvert.asmx"];
          NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
          NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

          [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
          [theRequest addValue: @"http://tempuri.org/CelsiusToFahrenheit" forHTTPHeaderField:@"SOAPAction"];
          [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
          [theRequest setHTTPMethod:@"POST"];
          [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

          NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

          if( theConnection )

          webData = [[NSMutableData data] retain];

          else

          NSLog(@"theConnection is NULL");



          After firing the request we can collect the XML response in the NSURLConnection’s delegate methods.



          -(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 with 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];
          NSLog(@"%@",theXML);
          [theXML release];



          After collecting the XML response in theXML string in -(void)connectionDidFinishLoading:(NSURLConnection *)connection
          we can parse this string using TBXML for any other XML parser you like.






          share|improve this answer




















          • I have added this code and able to run it too but am also getting array as the return param and i need to capture the array list.
            – Selwyn
            Dec 9 '11 at 13:35










          • can you please post the response here?
            – Saurabh
            Dec 9 '11 at 13:39










          • I am not sure how you are getting an array in webservice response? are you getting that in xml format?
            – Saurabh
            Dec 9 '11 at 13:41










          • no i mean I want to process and array list which is returned form the web service i ned to handle it in the iPhone code how do i work on that.
            – Selwyn
            Dec 12 '11 at 5:58










          • I am not sure how you are getting array in response (sorry I don't have any .net exp). But if you are talking about getting this data from xml response you can look at this very good library TBXML - tbxml.co.uk
            – Saurabh
            Dec 12 '11 at 6:52










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f8445755%2fhow-to-post-and-get-asmx-web-serivce-access-using-iphone-app%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote













          I think asmx webservices are SOAP webservices you should read my blog entry here -



          http://www.makebetterthings.com/iphone/call-soap-web-service-from-iphone/



          To call a SOAP service first i create a string with the SOAP request as follows.



           NSString *soapMessage = @"<?xml version="1.0" encoding="utf-8"?>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"
          "<CelsiusToFahrenheit xmlns="http://tempuri.org/">n"
          "<Celsius>50</Celsius>n"
          "</CelsiusToFahrenheit>n"
          "</soap:Body>n"
          "</soap:Envelope>n";


          After creating the SOAP request I create a NSMutableRequest to send this request to server.

          NSURL *url = [NSURL URLWithString:@"http://w3schools.com/webservices/tempconvert.asmx"];
          NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
          NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

          [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
          [theRequest addValue: @"http://tempuri.org/CelsiusToFahrenheit" forHTTPHeaderField:@"SOAPAction"];
          [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
          [theRequest setHTTPMethod:@"POST"];
          [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

          NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

          if( theConnection )

          webData = [[NSMutableData data] retain];

          else

          NSLog(@"theConnection is NULL");



          After firing the request we can collect the XML response in the NSURLConnection’s delegate methods.



          -(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 with 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];
          NSLog(@"%@",theXML);
          [theXML release];



          After collecting the XML response in theXML string in -(void)connectionDidFinishLoading:(NSURLConnection *)connection
          we can parse this string using TBXML for any other XML parser you like.






          share|improve this answer




















          • I have added this code and able to run it too but am also getting array as the return param and i need to capture the array list.
            – Selwyn
            Dec 9 '11 at 13:35










          • can you please post the response here?
            – Saurabh
            Dec 9 '11 at 13:39










          • I am not sure how you are getting an array in webservice response? are you getting that in xml format?
            – Saurabh
            Dec 9 '11 at 13:41










          • no i mean I want to process and array list which is returned form the web service i ned to handle it in the iPhone code how do i work on that.
            – Selwyn
            Dec 12 '11 at 5:58










          • I am not sure how you are getting array in response (sorry I don't have any .net exp). But if you are talking about getting this data from xml response you can look at this very good library TBXML - tbxml.co.uk
            – Saurabh
            Dec 12 '11 at 6:52














          up vote
          1
          down vote













          I think asmx webservices are SOAP webservices you should read my blog entry here -



          http://www.makebetterthings.com/iphone/call-soap-web-service-from-iphone/



          To call a SOAP service first i create a string with the SOAP request as follows.



           NSString *soapMessage = @"<?xml version="1.0" encoding="utf-8"?>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"
          "<CelsiusToFahrenheit xmlns="http://tempuri.org/">n"
          "<Celsius>50</Celsius>n"
          "</CelsiusToFahrenheit>n"
          "</soap:Body>n"
          "</soap:Envelope>n";


          After creating the SOAP request I create a NSMutableRequest to send this request to server.

          NSURL *url = [NSURL URLWithString:@"http://w3schools.com/webservices/tempconvert.asmx"];
          NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
          NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

          [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
          [theRequest addValue: @"http://tempuri.org/CelsiusToFahrenheit" forHTTPHeaderField:@"SOAPAction"];
          [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
          [theRequest setHTTPMethod:@"POST"];
          [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

          NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

          if( theConnection )

          webData = [[NSMutableData data] retain];

          else

          NSLog(@"theConnection is NULL");



          After firing the request we can collect the XML response in the NSURLConnection’s delegate methods.



          -(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 with 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];
          NSLog(@"%@",theXML);
          [theXML release];



          After collecting the XML response in theXML string in -(void)connectionDidFinishLoading:(NSURLConnection *)connection
          we can parse this string using TBXML for any other XML parser you like.






          share|improve this answer




















          • I have added this code and able to run it too but am also getting array as the return param and i need to capture the array list.
            – Selwyn
            Dec 9 '11 at 13:35










          • can you please post the response here?
            – Saurabh
            Dec 9 '11 at 13:39










          • I am not sure how you are getting an array in webservice response? are you getting that in xml format?
            – Saurabh
            Dec 9 '11 at 13:41










          • no i mean I want to process and array list which is returned form the web service i ned to handle it in the iPhone code how do i work on that.
            – Selwyn
            Dec 12 '11 at 5:58










          • I am not sure how you are getting array in response (sorry I don't have any .net exp). But if you are talking about getting this data from xml response you can look at this very good library TBXML - tbxml.co.uk
            – Saurabh
            Dec 12 '11 at 6:52












          up vote
          1
          down vote










          up vote
          1
          down vote









          I think asmx webservices are SOAP webservices you should read my blog entry here -



          http://www.makebetterthings.com/iphone/call-soap-web-service-from-iphone/



          To call a SOAP service first i create a string with the SOAP request as follows.



           NSString *soapMessage = @"<?xml version="1.0" encoding="utf-8"?>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"
          "<CelsiusToFahrenheit xmlns="http://tempuri.org/">n"
          "<Celsius>50</Celsius>n"
          "</CelsiusToFahrenheit>n"
          "</soap:Body>n"
          "</soap:Envelope>n";


          After creating the SOAP request I create a NSMutableRequest to send this request to server.

          NSURL *url = [NSURL URLWithString:@"http://w3schools.com/webservices/tempconvert.asmx"];
          NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
          NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

          [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
          [theRequest addValue: @"http://tempuri.org/CelsiusToFahrenheit" forHTTPHeaderField:@"SOAPAction"];
          [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
          [theRequest setHTTPMethod:@"POST"];
          [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

          NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

          if( theConnection )

          webData = [[NSMutableData data] retain];

          else

          NSLog(@"theConnection is NULL");



          After firing the request we can collect the XML response in the NSURLConnection’s delegate methods.



          -(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 with 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];
          NSLog(@"%@",theXML);
          [theXML release];



          After collecting the XML response in theXML string in -(void)connectionDidFinishLoading:(NSURLConnection *)connection
          we can parse this string using TBXML for any other XML parser you like.






          share|improve this answer












          I think asmx webservices are SOAP webservices you should read my blog entry here -



          http://www.makebetterthings.com/iphone/call-soap-web-service-from-iphone/



          To call a SOAP service first i create a string with the SOAP request as follows.



           NSString *soapMessage = @"<?xml version="1.0" encoding="utf-8"?>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"
          "<CelsiusToFahrenheit xmlns="http://tempuri.org/">n"
          "<Celsius>50</Celsius>n"
          "</CelsiusToFahrenheit>n"
          "</soap:Body>n"
          "</soap:Envelope>n";


          After creating the SOAP request I create a NSMutableRequest to send this request to server.

          NSURL *url = [NSURL URLWithString:@"http://w3schools.com/webservices/tempconvert.asmx"];
          NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
          NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

          [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
          [theRequest addValue: @"http://tempuri.org/CelsiusToFahrenheit" forHTTPHeaderField:@"SOAPAction"];
          [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
          [theRequest setHTTPMethod:@"POST"];
          [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

          NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

          if( theConnection )

          webData = [[NSMutableData data] retain];

          else

          NSLog(@"theConnection is NULL");



          After firing the request we can collect the XML response in the NSURLConnection’s delegate methods.



          -(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 with 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];
          NSLog(@"%@",theXML);
          [theXML release];



          After collecting the XML response in theXML string in -(void)connectionDidFinishLoading:(NSURLConnection *)connection
          we can parse this string using TBXML for any other XML parser you like.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 9 '11 at 13:22









          Saurabh

          19.6k1275128




          19.6k1275128











          • I have added this code and able to run it too but am also getting array as the return param and i need to capture the array list.
            – Selwyn
            Dec 9 '11 at 13:35










          • can you please post the response here?
            – Saurabh
            Dec 9 '11 at 13:39










          • I am not sure how you are getting an array in webservice response? are you getting that in xml format?
            – Saurabh
            Dec 9 '11 at 13:41










          • no i mean I want to process and array list which is returned form the web service i ned to handle it in the iPhone code how do i work on that.
            – Selwyn
            Dec 12 '11 at 5:58










          • I am not sure how you are getting array in response (sorry I don't have any .net exp). But if you are talking about getting this data from xml response you can look at this very good library TBXML - tbxml.co.uk
            – Saurabh
            Dec 12 '11 at 6:52
















          • I have added this code and able to run it too but am also getting array as the return param and i need to capture the array list.
            – Selwyn
            Dec 9 '11 at 13:35










          • can you please post the response here?
            – Saurabh
            Dec 9 '11 at 13:39










          • I am not sure how you are getting an array in webservice response? are you getting that in xml format?
            – Saurabh
            Dec 9 '11 at 13:41










          • no i mean I want to process and array list which is returned form the web service i ned to handle it in the iPhone code how do i work on that.
            – Selwyn
            Dec 12 '11 at 5:58










          • I am not sure how you are getting array in response (sorry I don't have any .net exp). But if you are talking about getting this data from xml response you can look at this very good library TBXML - tbxml.co.uk
            – Saurabh
            Dec 12 '11 at 6:52















          I have added this code and able to run it too but am also getting array as the return param and i need to capture the array list.
          – Selwyn
          Dec 9 '11 at 13:35




          I have added this code and able to run it too but am also getting array as the return param and i need to capture the array list.
          – Selwyn
          Dec 9 '11 at 13:35












          can you please post the response here?
          – Saurabh
          Dec 9 '11 at 13:39




          can you please post the response here?
          – Saurabh
          Dec 9 '11 at 13:39












          I am not sure how you are getting an array in webservice response? are you getting that in xml format?
          – Saurabh
          Dec 9 '11 at 13:41




          I am not sure how you are getting an array in webservice response? are you getting that in xml format?
          – Saurabh
          Dec 9 '11 at 13:41












          no i mean I want to process and array list which is returned form the web service i ned to handle it in the iPhone code how do i work on that.
          – Selwyn
          Dec 12 '11 at 5:58




          no i mean I want to process and array list which is returned form the web service i ned to handle it in the iPhone code how do i work on that.
          – Selwyn
          Dec 12 '11 at 5:58












          I am not sure how you are getting array in response (sorry I don't have any .net exp). But if you are talking about getting this data from xml response you can look at this very good library TBXML - tbxml.co.uk
          – Saurabh
          Dec 12 '11 at 6:52




          I am not sure how you are getting array in response (sorry I don't have any .net exp). But if you are talking about getting this data from xml response you can look at this very good library TBXML - tbxml.co.uk
          – Saurabh
          Dec 12 '11 at 6:52

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f8445755%2fhow-to-post-and-get-asmx-web-serivce-access-using-iphone-app%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          How to read a connectionString WITH PROVIDER in .NET Core?

          In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

          Museum of Modern and Contemporary Art of Trento and Rovereto