0

我正在为 ios 开发约会应用程序。我使用 .net Web 服务从数据库中获取数据。我在 Android 和 Windows Phone 应用程序上使用过它,但我还不能在 ios 上使用它。它返回具有子对象列表的对象列表。

例如,FirmaGetir 方法有一个参数:firID(字符串)。如何将参数传递给 Web 服务?如何解析这些项​​目?我需要一个示例代码。感谢关注。

网络服务请求

POST /webservice1.asmx HTTP/1.1
Host: example.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <FirmaGetir xmlns="http://tempuri.org/">
      <firID>string</firID>
    </FirmaGetir>
  </soap12:Body>
</soap12:Envelope>

网络服务结果

HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <FirmaGetirResponse xmlns="http://tempuri.org/">
      <FirmaGetirResult>
        <Firma>
          <firma_adi>string</firma_adi>
          <adres>string</adres>
          <telefon>string</telefon>
          <id>string</id>
          <sektor>string</sektor>
          <alt_sektor>string</alt_sektor>
          <alt_sektor_adi>string</alt_sektor_adi>
          <servis>string</servis>
          <map>string</map>
          <slogan>string</slogan>
          <sayfaGosterimi>int</sayfaGosterimi>
          <gpsilce>string</gpsilce>
          <gpssemt>string</gpssemt>
          <gpspk>string</gpspk>
          <duyuru>
            <baslik>string</baslik>
            <icerik>string</icerik>
            <link>string</link>
            <image>string</image>
          </duyuru>
          <firma_link>
            <tam_adi>string</tam_adi>
            <kisa_adi>string</kisa_adi>
            <firma_link>string</firma_link>
          </firma_link>
        </Firma>
      </FirmaGetirResult>
    </FirmaGetirResponse>
  </soap12:Body>
</soap12:Envelope>
4

2 回答 2

0

使用touchXml文件导出到您的项目

并根据您的要求修改以下方法

    - (NSArray *) parseAllShopInfoResponse:(NSString *)AllShopInfoResponse
{


    NSMutableArray *allShopInfoDTOArray = [[NSMutableArray alloc]init];


    CXMLDocument *inventoryResponseObject = [[CXMLDocument alloc] initWithXMLString:AllShopInfoResponse options:0 error:nil];

    NSArray *resultNodes = [inventoryResponseObject nodesForXPath:@"//shopsListDTO" error:nil];

//    NSLog(@"ShopsList nodes: %@", resultNodes);

    for (CXMLElement *resultElement in resultNodes)
    {
        NSMutableDictionary *allShopInfo = [[NSMutableDictionary alloc] init];

        for(int counter = 0; counter < [resultElement childCount]; counter++)
        {

            if ([[resultElement childAtIndex:counter] stringValue] == nil) 
            {
                [allShopInfo setObject:@" " forKey:[[resultElement childAtIndex: counter] name]];
            }
            else
            {
                [allShopInfo setObject:[[resultElement childAtIndex:counter] stringValue] forKey:[[resultElement childAtIndex:counter] name]];
            }

//            NSLog(@"ShopsList DIC %@",allShopInfo);

        }
        [allShopInfoDTOArray addObject:[allShopInfo copy]];


    }


    return [self returnAllShopInfoObjects:allShopInfoDTOArray];

}


- (NSArray*) returnAllShopInfoObjects: (NSArray *)allShopInfoArray
{

    NSMutableArray *allShopInfoObjects=[[NSMutableArray alloc]init];

    for (NSDictionary *allShopInfoDictionary in allShopInfoArray) 
    {

//        NSLog(@"ALL Shop Info Dictionary .....%@",allShopInfoDictionary);

        allShopInfoObject = [[ShopBasicDetails alloc]init];

        allShopInfoObject.shopId = [[allShopInfoDictionary objectForKey:@"shopId"] intValue];
        allShopInfoObject.shopName = [allShopInfoDictionary objectForKey:@"shopName"];
        allShopInfoObject.onlineStatus = [[allShopInfoDictionary objectForKey:@"onlineStatus"]intValue];
        allShopInfoObject.shopDetailsDownloadTime = (NSDate *)[allShopInfoDictionary objectForKey:@"dateTime"];
        allShopInfoObject.shopLatitudeValue = [[allShopInfoDictionary objectForKey:@"latitude"]doubleValue];
        allShopInfoObject.shopLongitudeValue = [[allShopInfoDictionary objectForKey:@"longitude"]doubleValue];
        NSURL *thunmbnailImageUrl = [NSURL URLWithString: [allShopInfoDictionary objectForKey:@"logoThumbnailUrl"]];
        UIImage *thunmbnailImage = [UIImage imageWithData: [NSData dataWithContentsOfURL:thunmbnailImageUrl]];

        allShopInfoObject.thumbnailImage =  thunmbnailImage;
        CLLocation *shopLocation = [[CLLocation alloc] initWithLatitude:allShopInfoObject.shopLatitudeValue longitude:allShopInfoObject.shopLongitudeValue];

//        NSLog(@"Distance i meters: %f", [userCurrentPosition getDistanceFrom:shopLocation]);
        allShopInfoObject.distance = [userCurrentPosition getDistanceFrom:shopLocation]/1000;

        [allShopInfoObjects addObject:allShopInfoObject];



    }
//    NSLog(@"OBJECTS : %@",allShopInfoObjects);
    [outputDelegate ParserOutputDelegate:allShopInfoObjects];

    return allShopInfoObjects;
}
于 2013-02-13T14:39:30.180 回答
0

我试图解决这个问题大约一个星期。我不再搜索它了。使用 Web 服务的最佳方式是使用带有 JSON 的 WCF 服务。我找到了一个很好的例子。请按照本教程http://www.codeproject.com/Articles/405189/How-to-access-SQL-database-from-an-iPhone-app-Via

于 2013-02-15T15:58:20.783 回答