2012-01-23 66 views
0

我正在嘗試將XML數據發送到Web服務。但我沒有收到任何服務的迴應。當我試圖通過SOAPUI發送XML ...我得到了錯誤的「傳入參數failiure」 ..任何一個可以請檢查我的代碼,並指出我什麼我做錯了..在ios應用程序中訪問Web服務

- (void)viewDidLoad 
{ 
    NSString *Message = [NSString stringWithFormat: @"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" 
        "<SOAP-ENV:Envelope \n" 
         "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \n" 
        "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n" 
        "xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" \n" 
        "SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" \n" 
        "xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"> \n" 
        "<SOAP-ENV:Body> \n" 
        "<XMLGetReportParameters xmlns=\"http://PlusDiagnostics.Schemas.GetReportParameters\"><UserName xmlns="">USERNAME</UserName><Password xmlns="">PASSWORD</Password><List xmlns="">All</List></XMLGetReportParameters>" 
        "</SOAP-ENV:Body> \n" 
        "</SOAP-ENV:Envelope>" ]; 

    NSURL *url = [NSURL URLWithString:@"https://pathflexstage.plusdx.com/MobileReporting/GetPathologyReports.svc"]; 
    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url]; 
    NSString *msgLength = [NSString stringWithFormat:@"%d", [Message length]]; 
    NSLog(@"message length is %d",[Message length]); 

    [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 
    [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"]; 
    [theRequest setHTTPMethod:@"POST"]; 
    [theRequest addValue: @"http://tempuri.org/IGetPathologyReports/GetReports" forHTTPHeaderField:@"soapAction"]; 

    [theRequest setHTTPBody: [Message dataUsingEncoding:NSUTF8StringEncoding]]; 

    NSString *returnString = [[NSString alloc] initWithData:[NSURLConnection sendSynchronousRequest:theRequest returningResponse:nil error:nil] encoding:NSUTF8StringEncoding]; 

    // NSLog("return"); 
    NSLog(@"%@",returnString); 

    [super viewDidLoad]; 
} 
+0

您可能想要從代碼中刪除密碼。您是否嘗試過在桌面瀏覽器中將XML發送到服務器?像擴展名爲Poster的Firefox一樣? –

+0

我不同意這個被關閉,當我正在學習如何通過iphone/objective-c訪問web服務時,它會真的幫助我 – AnthonyBlake

回答

1

你會從服務器接收回來的東西,可能是一個錯誤。

聲明以下內容;

NSURLResponse *response = nil; 
NSError *error = nil; 

...然後讓你的請求像這樣;

NSString *returnString = [[NSString alloc] initWithData:[NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error] encoding:NSUTF8StringEncoding]; 

...如果您然後檢查響應和錯誤,您應該能夠找到您的問題的路線。

相關問題