I am trying to access a WCF service from a iPhone app but I am getting following error:
AFHTTPRequestOperation error: Error Domain=AFNetworkingErrorDomain Code=-1011 "Request failed: internal server error (500)" UserInfo=0x8c75b90 {NSErrorFailingURLKey=http://xxx.xxx.xx.xxx/accessserviceshost/servicecontroller/holdingslistservice.svc, AFNetworkingOperationFailingURLResponseErrorKey= { URL: http://xxx.xxx.xx.xxx/accessserviceshost/servicecontroller/holdingslistservice.svc } { status code: 500, headers { "Cache-Control" = private; "Content-Length" = 736; "Content-Type" = "text/xml; charset=utf-8"; Date = "Tue, 25 Mar 2014 10:14:58 GMT"; Server = "Microsoft-IIS/6.0"; "X-AspNet-Version" = "4.0.30319"; "X-Powered-By" = "ASP.NET"; } }, NSLocalizedDescription=Request failed: internal server error (500)}
Following is my code to access the service:
NSURL *baseURL = [NSURL URLWithString:@"http://xxx.xxx.xx.xxx/accessserviceshost/servicecontroller/holdingslistservice.svc"];
NSString *soapBody = [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><HoldingsListInput xmlns=\"http://tempuri.org/\">"
"<Account_Id>1000</Account_Id>"
"<Allow_Global_Processing_Fl></Allow_Global_Processing_Fl>"
"<Asset_Class_Cd></Asset_Class_Cd>"
"<Cash_Balances_Cd>Y</Cash_Balances_Cd>"
"<Display_Cd>TA</Display_Cd>"
"<Industry_Class_Cd>30</Industry_Class_Cd>"
"<Invested_Income_Portfolio_Cd>Y</Invested_Income_Portfolio_Cd>"
"<Local_Fl>Y</Local_Fl>"
"<Positions_As_Of_Cd>TD</Positions_As_Of_Cd>"
"<Principal_Portfolio_Cd>Y</Principal_Portfolio_Cd>"
"<Security_Tp>48</Security_Tp>"
"<Show_Position_Instructions_Fl>Y</Show_Position_Instructions_Fl>"
"<Sort_Cd>MA</Sort_Cd>"
"<Unique_Assets_Only_Cd>Y</Unique_Assets_Only_Cd>"
"<Very_Liquid_Asset_Classes_Cd>X</Very_Liquid_Asset_Classes_Cd>"
"</HoldingsListInput></soap:Body></soap:Envelope>"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:baseURL];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[soapBody dataUsingEncoding:NSUTF8StringEncoding]];
[request addValue:@"http://tempuri.org/RetrieveHoldingList" forHTTPHeaderField:@"SOAPAction"];
[request addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSString *string = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSLog(@"%@", string);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"%s: AFHTTPRequestOperation error: %@", __FUNCTION__, error);
}];
[operation start];
I have checked service with same input on an asp.net page and it works there but I am not able to run it on the iPhone app.
SOAPUI came to my rescue. There was a flaw in the JASON. I used SOAPUI to build request and other parameters need for it and it worked fine for me.