0

我有一个 WCF 服务:

http://parentportal.technologyorg.com/ParentPortal.svc

我必须访问并获取数据。但不幸的是,我得到了一些 HTML 代码。

我的代码如下

-(IBAction)doit:(id)sender{

    NSString *soapMessage = [NSString stringWithFormat:@"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://parentportal.technologyorg.com/ParentPortal.svc\"><SOAP-ENV:Body><GetDictionary></GetDictionary></SOAP-ENV:Body></SOAP-ENV:Envelope>"];

    NSURL *url = [NSURL URLWithString:@"http://parentportal.technologyorg.com/ParentPortal.svc"];
                  NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
                  NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

                  [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
                  [theRequest addValue: @"GetStudentTerms" forHTTPHeaderField:@"SOAPAction"];
                  [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
                  [theRequest setHTTPMethod:@"POST"];
                  [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
    NSLog(@"%@",theRequest);
                  NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    if (theConnection) {
     webData = [NSMutableData data] ;
    }
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    NSLog(@"___didReceiveResponse");
    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
    NSLog(@"Status code %d", [httpResponse statusCode]);

    [webData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    NSLog(@"___didReceiveData");
    [webData appendData:data];
    NSLog(@"%@",webData);
}

- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
    NSLog(@"___connectionDidFinishLoading");
    NSLog(@"DONE. Received Bytes: %d", [webData length]);
    NSString *xmlData = [[NSString alloc]
                         initWithBytes:[webData mutableBytes]
                         length:[webData length]
                         encoding:NSUTF8StringEncoding];

}

NSLog如果我是一些 HTML 代码的输出,我不确定出了什么问题。

谁可以帮我这个事。

4

1 回答 1

1

试用SudzC基于 SOAP 的 Web 服务定义 WSDL 文件

用于 iPhone 开发的 Objective-C 库的代码生成。

请按照以下步骤操作

在此处输入图像描述

在此处输入图像描述

于 2013-01-24T05:07:19.203 回答