I am making an iPad application and using NSURlConnection to connect to one of my web services to retrieve some data from the server. I am calling the webservice in such a way that it retrieves 20 records each time.
Sometimes after 10-12 calls the NSURLConnection the DidFailWithError delegate will be called. The error log says:
The Internet connection appears to be offline
I have a retry button there as well. I keep on retrying but it keeps on getting the same error and goes to DidFailWithError.
Can anybody tell me what the problem is?
Here is the code I am using:
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:#"%d", [soap length]];
[theRequest addValue: #"text/xml; charset=utf-8" forHTTPHeaderField:#"Content-Type"];
[theRequest addValue: #"get_all_user_groups" forHTTPHeaderField:#"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:#"Content-Length"];
[theRequest setHTTPMethod:#"POST"];
[theRequest setHTTPBody: [soap dataUsingEncoding:NSUTF8StringEncoding]];
NSUrlConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
Related
I've been trying to get my iPhone application to talk to a WCF service. My application successfully connects/finds the web service, but, never seems to get a non-error response back. When I use visual studios wcf tester it works fine.
Xml format: <mAccess><user></user><pwd></pwd></mAccess>
Is there something wrong with how I'm structuring my head/body?
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:website]];
[request setHTTPMethod:#"POST"];
[request setValue:#"text/xml; charset=utf-8" forHTTPHeaderField:#"Content-type"];
NSString *soapMessage = [[NSString alloc] initWithFormat:#"<SOAP-ENV:Envelope
xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Body>
<MobileAccess xmlns=\"http://tempuri.org/\"><mAccess><user>user</user><pwd>pwd</pwd><custID>0</custID></mAccess>
</MobileAccess></SOAP-ENV:Body></SOAP-ENV:Envelope>"];
[request setValue:[NSString stringWithFormat:#"%d",[soapMessage length]] forHTTPHeaderField:#"Content-length"];
[request addValue:#"http://tempuri.org/IProviderDataService/MobileAccess" forHTTPHeaderField:#"Soapaction"];
[request setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
There is one potential error in your construction of the URL request: The "Content-Length" must be set to the length of the HTTP body. This might be different from [soapMessage length] if non-ASCII characters in the message are converted to UTF-8.
So you should use the length of the data after the conversion:
NSData *bodyData = [soapMessage dataUsingEncoding:NSUTF8StringEncoding];
[request setValue:[NSString stringWithFormat:#"%d",[bodyData length]] forHTTPHeaderField:#"Content-length"];
[request setHTTPBody:bodyData];
i am trying the following code, soap web service.It is not working .
please help me out.
Link
Service
NSString *soapMessage = [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"
"<request xmlns=\"http://searchupc.com/GenerateBarcode\">\n"
"<auth>5ggpf54TRghbnIvqS2XVGQQ0q6qCNuJ</auth>\n"
"<method>FetchProductByUPC</method>"
"<params>"
"<upc>026274920257</upc>"
"</params>"
"</request>\n"
"</soap:Body>\n"
"</soap:Envelope>\n"
];
NSLog(soapMessage);
NSURL *url = [NSURL URLWithString:#"http://www.simpleupc.com/api/"];
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://searchupc.com/GenerateBarcode/" forHTTPHeaderField:#"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:#"Content-Length"];
[theRequest setHTTPMethod:#"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSLog(#"SOAP CONNECTED qqq%#",theRequest);
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
Check http://sudzc.com/ . it will generate xcode project for you.
1: Type the web address of the WSDL to convert (if Protected, then enter username and password )
2: Choose the type of code bundle to create (Objective c) and download.
Just drag and drop the 'Generated' folder to your project and access all the SOAP messages.
Try this. its really easy and simple.
I've found wsdlToObjc pretty good. It generates client side ObjC bindings for you from WSDL. You can download it at http://code.google.com/p/wsdl2objc/. The link http://www.priyaontech.com/2012/10/soap-based-webservices-integration-in-an-ios-app/ explains its usage with an example project.
2012-07-27 20:15:53.523 ProjectDemo[1697:40b] Done. received Bytes 0
2012-07-27 20:15:53.524 ProjectDemo[1697:40b] the xml Data is
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:#"%d",[soapMessage length]];
[theRequest addValue:#"text/xml" forHTTPHeaderField:#"Content-Type"];
[theRequest addValue:#"ManageCase" forHTTPHeaderField:#"SOAPAction"];
[theRequest addValue:msgLength forHTTPHeaderField:#"Content-Length"];
[theRequest setHTTPMethod:#"POST"];
[theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
i am getting response from soap envelop is 0.
Can any one advice me for what cases the response will 0.
#thanks in advance
Try using "text/xml; charset=utf-8" for your Content-Type header field value.
Also try including your whole namespace as part of the SOAPAction header, E.g. "http://www.yournamespace.com/ManageCase"
Here's a SOAP 1.1 Objective-C code sample:
NSString *soapAction = #"Login";
NSString *messageLength = [NSString stringWithFormat:#"%d", [message length]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:serverURL];
[request addValue:#"text/xml; charset=utf-8" forHTTPHeaderField:#"Content-Type"];
[request addValue:[NSString stringWithFormat:#"http://www.namespace.com/%#", soapAction] forHTTPHeaderField:#"SOAPAction"];
[request addValue:messageLength forHTTPHeaderField:#"Content-Length"];
[request setHTTPMethod:#"POST"];
[request setHTTPBody:[message dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
I am parsing a soap web service for authentication but it is not returining any NSData so that I can writex xml parser for it.
Please let me know what I'm doing wrong.
Here is my code:
**
-(void)getAdvertisment
{
NSString* soapMesasge=
[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>"
"<GetAdvertisement xmlns=\"http://tempuri.org/\" />"
"</soap:Body>"
"</soap:Envelope>"];**
NSURL* url=[NSURL URLWithString:#"http://codeexsolutions.com/HosService/ServiceHOSProvider.asmx"];
NSMutableURLRequest* theRequest=[NSMutableURLRequest requestWithURL:url];
NSString* msgLength=[NSString stringWithFormat:#"%d",[soapMesasge length]];
[theRequest addValue:#"text/xml" forHTTPHeaderField:#"Content-Type"];
[theRequest addValue:#"http://tempuri.org/GetAdvertisement" forHTTPHeaderField:#"SOAPAction"];
[theRequest addValue:msgLength forHTTPHeaderField:#"Content-Length"];
[theRequest setHTTPMethod:#"POST"];
[theRequest setHTTPBody:[soapMesasge dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection)
{
webData =[[NSMutableData alloc]retain];
}
else
{
// Inform the user that the connection failed.
}
}
NSURLConnection is an asynchronous method - have you implemented the rest of the delegate methods needed to actually listen for and retrieve the data?
You may wish to review the documentation here
In your example above, webData will always be empty, it's up to you to populate it...
I am try to connect webservices to my code i got error as
"Server did not recognize the value of HTTP Header SOAPAction"
NSString *soapMessage = [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"
"<Hello xmlns=\"http://viium.com/\">\n"
"<name>%#</name>\n"
"</Hello>\n"
"</soap:Body>\n"
"</soap:Envelope>\n", #"new"
];
NSLog(soapMessage);
NSURL *url = [NSURL URLWithString:#"http://viium.com/WebService/HelloWorld.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://viium.com/Hello" forHTTPHeaderField:#"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:#"Content-Length"];
[theRequest setHTTPMethod:#"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
Please guide me what iam missing?
NSURL *url = [NSURL URLWithString:#"https://servername.com/WebService/WebServicename.asmx"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:#"%d",[soapMessage length]];
[theRequest addValue:#"text/xml" forHTTPHeaderField:#"Content-Type"];
[theRequest addValue:#"servername.com/Hello" forHTTPHeaderField:#"SOAPAction"];
[theRequest addValue:msgLength forHTTPHeaderField:#"Content-Length"];
[theRequest setHTTPMethod:#"POST"];
[theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
here is the link,
http://abhicodehelp.blogspot.com/2010/12/handling-soap-with-iphone.html
this may help you..
If it's your own web-service, check whether your "servername.com/Hello" in query equals namespace in Web-Service.
In ASP.Net it defines like:
[WebService(Namespace="servername.com/Hello")]