質問

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.

役に立ちましたか?

解決 2

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.

他のヒント

-Try This way . IT might help. Edit your Soap Request string in this manner , may be problem lies in that .

NSString *soapRequest =[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"
    "<Login xmlns=\"http://tempuri.org/\">\n"
    "<UID>%@</UID>\n"
    "<Password>%@</Password>\n"
    "</Login>\n"
    "</soap:Body>\n"
    "</soap:Envelope>\n",@"Test",@"Test"];


    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
        [request addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request addValue:@"http://tempuri.org/RetrieveHoldingList" forHTTPHeaderField:@"SOAPAction"];
        NSString *msgLength = [NSString stringWithFormat:@"%lu",(unsigned long)[soapRequest length]];
        [request addValue:msgLength forHTTPHeaderField:@"Content-Length"];
        [request setHTTPMethod:@"POST"];
        [request setHTTPBody:[soapRequest dataUsingEncoding:NSUTF8StringEncoding]];
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top