我正在尝试从iPhone应用程序访问WCF服务,但我收到以下错误:
AFHTTPRequestOperation错误:错误域= AFNetworkingErrorDomain代码= -1011“请求失败:内部服务器错误(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代码:500,headers { “Cache-Control”=私有; “内容长度”= 736; “Content-Type”=“text / xml; charset = utf-8”; 日期=“星期二,2014年3月25日10:14:58 GMT”; Server =“Microsoft-IIS / 6.0”; “X-AspNet-Version”=“4.0.30319”; “X-Powered-By”=“ASP.NET”; ,NSLocalizedDescription =请求失败:内部服务器错误(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 :(得分:0)
- 试试这种方式。 IT可能有所帮助。以这种方式编辑你的Soap Request字符串,可能就是问题所在。
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]];
答案 1 :(得分:0)
SOAPUI来救我。 JASON有一个缺陷。我使用SOAPUI构建请求和其他需要的参数,它对我来说很好。