1

I want to access a webservice, want to pass 2 parameters.

When I run the code below, this error is shown:

@countryname not supplied

I already pass 2 parameters as txtcity and txtcountry.

-(IBAction)FindWords:(id)sender
{
NSString *soapMsg =    
[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>"

 "<GetWeather xmlns=\"http://www.webserviceX.NET/\">"

 "<CityName>%@</CityName>"

 "<CountryName>%@</CountryName>"

 "</GetWeather>"  

 "</soap:Body>"

 "</soap:Envelope>", txtCity.text,txtCounrty.text];

//---print it to the Debugger Console for verification---
NSLog(@"%@",soapMsg);

NSURL *url = [NSURL URLWithString:
              @"http://www.webservicex.net/globalweather.asmx"];

NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
              //---set the various headers---
              NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMsg length]];
 NSLog(@"WebData....%@",soapMsg);
              [req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
              [req addValue:@"http://www.webserviceX.NET/GetWeather" forHTTPHeaderField:@"SOAPAction"];

               [req addValue:msgLength forHTTPHeaderField:@"Content-Length"];

               //---set the HTTP method and body---

               [req setHTTPMethod:@"POST"];

               [req setHTTPBody:[soapMsg dataUsingEncoding:NSUTF8StringEncoding]];

               //---start animating--
               [activityIndicator startAnimating];

               conn = [[NSURLConnection alloc] initWithRequest:req                                                          delegate:self];

               if(conn)
               {                   
               webData = [[NSMutableData data] retain];

                    NSLog(@"WebDatanew....%@",webData);

               }
}
1
  • It shows no data found
    – Muju
    Dec 10, 2016 at 6:47

5 Answers 5

2

just include ASIHTTPRequest.Its much more easier to use.

http://allseeing-i.com/ASIHTTPRequest/
0

the web service takes three parameters:

rw_app_id: The unique identifier for the app. If you’ve been following along with the previous tutorial, there should be only one entry so far, App ID #1.
code: The code to attempt to redeem. This should be a string that’s entered by the user.
device_id: The device ID that is attempting to redeem this code. We can get this with an easy API call.

use:- ASIHTTPRequest

1
0

change your soapMsg format :

NSString *soapMsg = [NSString stringWithFormat:
                         @"<?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"
                         "<GetWeather xmlns=\"http://www.webserviceX.NET\">\n"
                         "<CityName>%@</CityName>"
                         "<CountryName>%@</CountryName>\n"
                         "</GetWeather>\n"
                         "</soap:Body>\n"
                         "</soap:Envelope>\n",txtCity.text,txtCounrty.text];
0

Use ASIHTTP Request and JSON Library to communicate with your web service. JSON is way better than XML feeds and its very easy to handle.

Download JSON library form Here

Here is the Documentation for ASIHTTP request :- http://allseeing-i.com/ASIHTTPRequest/

Hope this will help you. Thank you

0

May be this can help you. It contain one parameter

-(void)serverconnection{

   NSString *CountryName=@"India";

    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>"
                             "< GetWeather xmlns=\"http://tempuri.org/\">"
                             "<CountryName>%@</CountryName>"
                             "</GetWeather >"
                             "</soap:Body>"
                             "</soap:Envelope>",CountryName];

    NSURL *myNSUObj=[NSURL URLWithString:@"http://www.webservicex.net/globalweather.asmx?op=GetCitiesByCountry"];
    // NSURLRequest *myNSURequestObj=[NSURLRequest requestWithURL:myNSUObj];

    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:myNSUObj];
    NSString *msgLength = [NSString stringWithFormat:@"%lu", (unsigned long)[soapMessage length]];

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

    myNSUConnectionObj=[[NSURLConnection alloc]initWithRequest:theRequest delegate:self];
    NSLog(@"Data =%@",myNSUConnectionObj);
    if(myNSUConnectionObj)
    {

        NSLog(@"successful connection");
        myNSMDataFromServer=[[NSMutableData alloc]init];
    }
}

Your webservice is different but may be this can give you idea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.