Zugriff auf ASP.Net Json Webservice

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Zugriff auf ASP.Net Json Webservice

    Hallo zusammen,

    ich habe einen simplen Webservice auf meinem Windows 8.1 IIS laufen. Dieser soll mir anhand einer ID einen Kunden zurückgeben, also nur ein einziger Parameter. Ich bekomme dann ein Json - Object zurück, welches folgendermassen aussieht: [{"Zugang":"Zugang 1"},{"Name":"Kunde 1"}]. Beim lokalen Testformular funktioniert auch alles, aber ich versuche nun schon seit vier Tagen irgendwie mit iOS darauf zuzugreifen. Klar gibt es zig Tutorials im Netz, allerdings bekomme ich die irgendwie nicht ans laufen.

    LG

    Ralf
  • Zugriff auf ASP.Net Json Webservice

    Wie gesagt, ich habe mal versucht ein Tutorial an meine Bedürfnisse anzupassen:

    - (void)WebService
    {
    NSDictionary *inputData = [NSDictionary dictionaryWithObjectsAndKeys:@"8888", @"MLCCode", nil];

    NSError *error = nil;
    NSData *jsonInputData = [NSJSONSerialization dataWithJSONObject:inputData options:NSJSONWritingPrettyPrinted error:&error];
    NSString *jsonInputString = [[NSString alloc] initWithData:jsonInputData encoding:NSUTF8StringEncoding];

    NSURL *url = [NSURL URLWithString:@"http://ralf-8-pro-64/KundenService/WebServiceKunde.asmx/Kunde"];

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setHTTPMethod:@"POST"];
    [request setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:[jsonInputString dataUsingEncoding:NSUTF8StringEncoding]];
    NSURLResponse *response;
    NSError *err;
    NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];

    id jsonResponseData = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:nil];

    NSDictionary *jsonResponseDict;
    if ([jsonResponseData isKindOfClass:[NSDictionary class]])
    {
    jsonResponseDict = jsonResponseData;
    }
    else
    {

    }
    jsonResponseData = [jsonResponseDict objectForKey:@"d"];
    if (jsonResponseData == nil)
    {
    // Server may have returned a response containing an error
    // The "ExceptionType" value is returned from my .NET server used in sample
    id jsonExceptioTypeData = [jsonResponseDict objectForKey:@"ExceptionType"];
    if (jsonExceptioTypeData != nil) {
    NSLog(@"%s ERROR : Server returned an exception", __func__);
    NSLog(@"%s ERROR : Server error details = %@", __func__, jsonResponseDict);
    }
    }
    }

    responseData bleibt immer nil.

    Ralf