1

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

Community
  • 1
  • 1
Jasveer
  • 209
  • 2
  • 8

1 Answers1

0

- 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>&lt;silent&gt;&lt;action&gt;logon&lt;/action&gt;&lt;gameid&gt;mygame&lt;/gameid&gt;&lt;gpassword&gt;gamepwd&lt;/gpassword&gt;&lt;data&gt;&lt;username&gt;abcd@abc.com&lt;/username&gt;&lt;password&gt;a&lt;/password&gt;&lt;/data&gt;&lt;/silent&gt;</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]];
Tarsem Singh
  • 14,139
  • 7
  • 51
  • 71