2014-03-25 77 views
0

我想從一個iPhone應用程序訪問一個WCF服務,但我收到以下錯誤SOAP服務:無法訪問建立在WCF上iPhone

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)}

以下是我的代碼來訪問服務:

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]; 

我已經在asp.net網頁上檢查過相同的輸入服務,它在那裏工作,但我無法在iPhone應用程序上運行它。 有人可以幫助我嗎。過去幾天我一直在困擾這個問題。

問候
潘卡

回答

0

SOAPUI來救我。 JASON存在缺陷。我使用SOAPUI來構建請求和其他參數,它對我來說工作得很好。

0

- 嘗試這種方式。 IT可能會有幫助。以這種方式編輯你的肥皂請求字符串,可能是問題所在。

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]]; 
+0

我試過你提到的方式,但它仍然無法正常工作。 – pankaj

+0

查看編輯的Ans。 –

+0

我仍然收到同樣的錯誤。 – pankaj