我是一位經驗豐富的iOS開發人員,但擁有SOAP和各種HTTP協議的基本知識。如何調用Microsoft Dynamics NAV中的函數以使用AFNetworking2檢索XML
我有一位客戶創建了一個Microsoft Dynamics NAV接口,該接口將爲我提供iOS應用程序的一些XML。我將AFNetworking2用於網絡端,並使用NSXMLParser來解析XML。
解析器工作正常,但我努力從客戶端NAV URL獲取XML數據。
我相信我已經成功地對服務器進行了身份驗證,但我似乎無法調用將爲我返回XML數據的函數。我現在使用這段代碼來驗證: AFHTTPRequestOperationManager * manager = [AFHTTPRequestOperationManager manager];
NSURLCredential *credential = [NSURLCredential credentialWithUser:[AppController sharedAppController].authUserName
password:[AppController sharedAppController].authPassword
persistence:NSURLCredentialPersistenceForSession];
NSMutableURLRequest *request = [manager.requestSerializer requestWithMethod:@"POST"
URLString: @"http://xxx.xxx.xx.x:7056/DynamicsNAV_KPI/WS/Retail%20Company/Codeunit/Kiwi_KPI"
parameters:nil
error:nil];
manager.responseSerializer = [AFXMLParserResponseSerializer serializer];
[manager.requestSerializer setValue:@"application/xml" forHTTPHeaderField:@"Accept"];
[manager.requestSerializer setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];
AFHTTPRequestOperation *authenticationOperation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[authenticationOperation setCredential:credential];
[authenticationOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Authorisation Success!");
NSLog(@"Response XML: %@", [operation responseString]);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Authentication Failure: %@", error);
}];
這似乎讓我門作爲授權成功!消息出現在日誌中。我的客戶告訴我,我現在需要用兩個參數「user」(SERVER \ username)和一個空的對象/變量來調用「GetData_KPI」,該變量應該包含返回的xml。
我創建了一個我認爲是這項任務的SOAP消息:
NSString *soapMessage = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<soap:Envelope\n"
"xmlns:c=\"http://schemas.xmlsoap.org/soap/encoding/\"\n"
"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"\n"
"xmlns:n1=\"urn:microsoftdynamicsschemas/codeunit/Kiwi_KPI\">\n"
"<soap:Header></soap:Header>"
"<soap:Body>"
"<n1:GetDATA_KPI id=\"o0\" c:root=\"1\">"
"<n1:user>SERVER\\jdoe</n1:user>"
"<n1:kPIxml></n1:kPIxml>"
"</n1:GetData_KPI>"
"</soap:Body>"
"</soap:Envelope>"];
而且加入這2行代碼:
[request setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
[request addValue:soapMessage forHTTPHeaderField:@"SOAPAction"];
但是,當添加這兩條線的認證沒有按」將不起作用,我得到這樣的錯誤:
Authentication Failure: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: unsupported media type (415)" UserInfo=0x188635f0 {com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x177ba0f0> { URL: http://xxx.xxx.xx.xx:7056/DynamicsNAV_KPI/WS/Retail%20Company/Codeunit/Kiwi_KPI } { status code: 415, headers {
"Content-Length" = 0;
Date = "Tue, 16 Jun 2015 21:19:55 GMT";
Server = "Microsoft-HTTPAPI/2.0";
} }, NSErrorFailingURLKey=http://xxx.xxx.xx.x:7056/DynamicsNAV_KPI/WS/Retail%20Company/Codeunit/Kiwi_KPI, NSLocalizedDescription=Request failed: unsupported media type (415), com.alamofire.serialization.response.error.data=<>}
我的問題是:1。 何我是否使用AFNetworking調用函數GetDataKPI?
應該如何構造SOAP消息來傳遞用戶名和XML的空白參數?
我將如何訪問空白參數以獲取XML?
我真的對這個東西感到不知所措,非常感謝任何幫助。