2013-05-22 36 views
0

我嘗試調用WCF中創建的Web服務時遇到了麻煩,此服務由Mac os x應用調用。無法獲得來自WCF服務的響應

這是代碼

soapMessage = @"{name:\"Sergio\"}"; 

NSURL *url = [NSURL URLWithString:@"http://localhost/GSBonoServicios/GSBonoService.svc/HelloWorld"]; 
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url]; 
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]]; 
[theRequest setHTTPMethod: @"POST"]; 
[theRequest setValue:@"application/json" forHTTPHeaderField:@"Accept"]; 
[theRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 
NSData *requestData = [NSData dataWithBytes:[soapMessage UTF8String] length:[soapMessage length]]; 
[theRequest setHTTPBody:requestData]; 
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; 

連接成功,但沒有迴應,我嘗試推行一些教程,我期待在#1,我找到很多答案,但沒有什麼工作,我希望你可以幫我。

ps。我不說英語,但我希望我解釋說,由於

+0

供參考:'肥皂!= json' –

+0

感謝您的信息和對我的無知感到抱歉,但我沒有看到我使用肥皂的位置,我發現的例子或多或少都是您使用肥皂的方式,但如果您有任何其他想法,將不勝感激 –

+0

是您的wcf服務休息服務或肥皂之一? –

回答

0

我終於找到了解決問題的是服務,而工作的代碼是

NSString *[email protected]"Sergio"; 
NSDictionary *tmp = [[NSDictionary alloc] initWithObjectsAndKeys: name, @"name", 
       nil]; 
NSURL *url = [NSURL URLWithString:@"http://www.myserver.com/Servicio/ServicioEjemplo.svc/HelloWorld"]; 
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url]; 
[theRequest setHTTPMethod: @"POST"]; 
[theRequest setValue:@"application/json" forHTTPHeaderField:@"Accept"]; 
[theRequest setValue:@"applicat ion/json" forHTTPHeaderField:@"Content-Type"]; 
NSError *error; 
NSData *postdata = [NSJSONSerialization dataWithJSONObject:tmp options:kNilOptions error:&error]; 
[theRequest setHTTPBody:postdata]; 
NSLog(@"JSON summary: %@", [[NSString alloc] initWithData:postdata 
              encoding:NSUTF8StringEncoding]); 
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; 

感謝