Implement Soap Based Services with wsdl format in iOS? - ios

I have to implement the XML base soap service in my iOS application.i have goggled the things but dint find proper implementation. here is my URL of XML based WSDL service.
http://www.XXX.XX.XX/IntegrationService/MobileAppServicePort?wsdl
following is the response when we call this service in SOA Client
Service name: MobileAppIntegrationService
Description: undefined
Targetnamespace: http://integration.XXX.XXXX.XXX.XX/
Operations: (please choose one of the listed operations)
1. Operation: getNewsDetails
2. Operation: getNewsList
3. Operation: login
4. Operation: getRulesList
now can any one please tell me how can i implement this kind of web-service to post or get the data from above operations as i have never been to this XML based soap service.
we have tried following thing to use one opertaion of CreateUser
soapMessage = #"<?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><getCountriesList xmlns=\"http://integration.esi.dtps.gov.ae/\"></getCountriesList></soap:Body></soap:Envelope>";
//Now create a request to the URL
NSURL *url = [NSURL URLWithString:#""]; //<--
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:#"%d", [soapMessage length]];
//ad required headers to the request
[theRequest addValue:#"" forHTTPHeaderField:#"Host"];//<--
[theRequest addValue: #"text/xml; charset=utf-8" forHTTPHeaderField:#"Content-Type"];
[theRequest addValue: #"" forHTTPHeaderField:#"SOAPAction"];//<--
[theRequest addValue: msgLength forHTTPHeaderField:#"Content-Length"];
[theRequest setHTTPMethod:#"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
and we are confused that what to add in "HOST" "SOAPACTION" & "URL". can anyone please guide.

Related

To call a webservice from an iOS application

I want to make a simple iOS application which calls a Web service.
I reffered the following link
http://www.codeproject.com/Tips/622376/iOS-Soap-Webservice-Calling-and-Parsing-the-Respon
I tried to run the sample project that i got from this link.But I am getting the response like
"soap:ClientServer did not recognize the value of HTTP Header SOAPAction: http://tempuri.org/."
I am not able to find out what the reason behind this error is.And I am very much new to web services.Can anyone help me to solve this error?And someone please tell me ,what are the basic steps to call a web service from an iOS application.Is there any special version requirements of Xcode and iOS for calling web services?Please help me ...Thanks in advance for any help...
This is the code that I am using for sending the request
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"
" <CelsiusToFahrenheit xmlns=\"http://tempuri.org/\">\n"
"<Celsius>%#</Celsius>\n"
"</CelsiusToFahrenheit>\n"
"</soap:Body>\n"
"</soap:Envelope>\n" ,textFieldCelcisus.text];
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/" 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] ;
NSLog(#"webdata is %#",webData);
NSLog(#"Problem");
}
else
{
NSLog(#"theConnection is NULL");
}
Change this line:
[theRequest addValue: #"http://tempuri.org/" forHTTPHeaderField:#"SOAPAction"];
into:
[theRequest addValue: #"http://www.w3schools.com/webservices/CelsiusToFahrenheit" forHTTPHeaderField:#"SOAPAction"];
The server is complaining about the value for the SOAPAction. The SOAPAction's are defined in the WSDL, and are different for each operation.
Since you provided the service URL and the service is public, i just checked it.
The SOAPAction for 'CelsiusToFahrenheit' appeared to be:
http://www.w3schools.com/webservices/CelsiusToFahrenheit
Note that each operation has it's own SOAPAction, e.g.:
CelsiusToFahrenheit -> http://www.w3schools.com/webservices/CelsiusToFahrenheit
FahrenheitToCelsius -> http://www.w3schools.com/webservices/FahrenheitToCelsius
etc...
Above answer is right, only suggestion that use NSURLSession instead of NSURLConnection.

svc file and resultful web service

I am trying to make my iPhone application connect to my Webservices. I don't have much experience with this Webservices so this is why I ask here for information/help.
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">\n"
"<soap:Body>\n"
"<silent xmlns="http://tempuri.org/">"
"<action>logon</action>"
"<gameid>mygame</gameid>"
"<gpassword>gamepwd</gpassword>"
"<data>"
"<username>abc#abc.com</username>"
"<password>a</password>"
"</data>"
"</silent>"
"</soap:Body>"
"</soap:Envelope>"];
NSURL *url1 = [NSURL URLWithString:#"http://mywebsite.com/Service.svc"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url1];
NSString *msgLength1 = [NSString stringWithFormat:#"%d", [soapMessage length]];
[theRequest addValue: #"text/xml; charset=utf-8" forHTTPHeaderField:#"Content-Type"];
[theRequest addValue: #"http://tempuri.org/ISilentManagerAPI/Service" forHTTPHeaderField:#"Soapaction"];
[theRequest addValue: msgLength1 forHTTPHeaderField:#"Content-Length"];
[theRequest setHTTPMethod:#"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
This code always returns status code 415, what am I doing wrong?
PS.
Here is link which is working fine in Android getting java.io.IOException: HTTP request failed, HTTP status: 404 in ksoap2 while passing xml data to soap1.2 android
- Try This Which Will Surely Help You :
NSString *soapMessage = [NSString stringWithFormat:
#"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Body><Service xmlns=\"http://tempuri.org/\">"
"<xmlstring><silent><action>logon</action><gameid>mygame</gameid><gpassword>gamepwd</gpassword><data><username>abcd#abc.com</username><password>a</password></data></silent></xmlstring></Service>"
"</SOAP-ENV:Body>"
"</SOAP-ENV:Envelope>"];
NSURL *url1 = [NSURL URLWithString:#"http://mywebsite.com/Service.svc"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url1];
NSString *msgLength1 = [NSString stringWithFormat:#"%d", [soapMessage length]];
[theRequest addValue: #"text/xml; charset=utf-8" forHTTPHeaderField:#"Content-Type"];
[theRequest addValue: #"http://tempuri.org/ISilentManagerAPI/Service" forHTTPHeaderField:#"SOAPAction"];
[theRequest addValue: msgLength1 forHTTPHeaderField:#"Content-Length"];
[theRequest setHTTPMethod:#"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

IOS SDK + Youtube API + NoLinkedYouTubeAccount

I have add youtube APi in my application and I have successfully authorized my account and get access token from google via auth 2.0.
but now i want to add comment on video and i am getting error as below:
1. invalide token
2. NoLinkedYouTubeAccount
etc.
i thought, i am not able to correctly use and understand Authorization: Bearer ACCESS_TOKEN
statement of google and i am confusing how to pass my token with my call.
My code is as below:
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:#"%d", [soapMessage length]];
[theRequest addValue: #"application/atom+xml" forHTTPHeaderField:#"Content-Type"];
[theRequest addValue: msgLength forHTTPHeaderField:#"Content-Length"];
[theRequest addValue:[NSString stringWithFormat:#"Bearer %#",#"my token" forHTTPHeaderField:#"Authorization"];
[theRequest addValue: #"2" forHTTPHeaderField:#"GData-Version"];
[theRequest addValue: #"key=mykey" forHTTPHeaderField:#"X-GData-Key"];
[theRequest setHTTPMethod:#"POST"];
Can you help me to solve this issue and suggest me to call correct way?
Thanks
You may be trying to access with an Service account rather than an actual YouTube account.
You can check out Objective C samples from YouTube and use YouTube Objective-C client library.

Send parameters to web service

I have written a function to get a response from web service. But now I want to send parameters to a web service. How can I modify the code below to send parameters to another web service? I want to work with the below code, I am new to IOS and dont want to mess up since I have a working code.
- (IBAction)buttonClick:(id)sender {
recordResults = FALSE;
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"
"<GetUserList xmlns=\"http://methodoor.com/checkupservice/\" />\n"
"</soap:Body>\n"
"</soap:Envelope>\n"];
//NSLog(soapMessage);
_lbl_result.text = soapMessage;
NSURL *url = [NSURL URLWithString:#"http://servicing2.rotanet.com.tr/service.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://methodoor.com/checkupservice/GetUserList" 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");
}
//[nameInput resignFirstResponder];
}
I see you are accessing SOAP web services. And you are already sending data in to your web service in SOAP message.
As this is a SOAP API, you only need to change the SOAP Action [theRequest addValue: #"http://methodoor.com/checkupservice/GetUserList" forHTTPHeaderField:#"SOAPAction"]; and SOAP message, which you can get from the WSDL or SVC file, to access another method of your web service.
For more info you can have a look at this link. Hope this helps.

Why I can not get data from web service, I get feed back"List does not exist."

Below is the code to request web service, I get the feed back #"List does not exist. The page you selected contains a list that does not exist. It may have been deleted by another user."
NSString *soapMessage = #"<?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><GetList xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\"><listName>Contact</listName></GetList></soap:Body></soap:Envelope>";
NSString * wsURL = #"http://192.168.11.133/Jason/_vti_bin/Lists.asmx";
NSString *msgLength = [NSString stringWithFormat:#"%d", [soapMessage length]];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"%#",wsURL]];
ASIHTTPRequest * theRequest = [ASIHTTPRequest requestWithURL:url];
[theRequest addRequestHeader:#"Content-Type" value:#"text/xml; charset=utf-8"];
[theRequest addRequestHeader:#"SOAPAction" value:#"http://schemas.microsoft.com/sharepoint/soap/GetList"];
[theRequest setUsername:#"username"];
[theRequest setPassword:#"password"];
[theRequest addRequestHeader:#"Content-Length" value:msgLength];
[theRequest setRequestMethod:#"POST"];
[theRequest appendPostData:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
[theRequest setDefaultResponseEncoding:NSUTF8StringEncoding];
[theRequest setTimeOutSeconds:20];
[theRequest setDidFailSelector:#selector(onRequestFail:)];
[theRequest startSynchronous];
The webservice is from sharepoint.
I feel my code is correct. Can anyone give some advice? Thanks.
offtopic:
ASIHTTPRequest is not longer supported and for POST Request the is a class ASIFormDataRequest
Please note that I am no longer working on this library - you may want to consider using something else for new projects. :)
You could you an alternative like:
AFNetworking (my favorite choice)
MKNetworkKit
This should be SharePoint issue.
Using IP directly will cause some issues.
I solve the problem by mapping the host name.

Resources