Microsoft-HTTPAPI を使用して構築された Windows ベースの REST サーバーがあります (つまり、IIS で実行されていません)。
ブラウザー ベースの REST ツール (Firefox RESTClient) から JSON 要求をサービスに送信すると、サーバーは要求を受信し、Microsoft Service Trace Viewer からのトレースとサービスからの応答に従って正しく処理します。サービスから有効な JSON が返されます。
NSURLConnect を使用して非常に同じ JSON 要求をサービスに送信する iOS アプリケーションがありますが、常にタイムアウトします。WireShark を使用してトレースしましたが、どちらの場合も HTTP 要求は正しく形成され、サーバーに正しく送信されます。MS Trace Viewer を使用してトレースしましたが、「受信バイト」に入りますが、戻りません。最終的に WCF サーバーを閉じると例外が発生します。iOS アプリを閉じると例外が返されません。
NSURLConnection sendSynchronousRequest を使用して、コールバックを非同期に使用し、完了ブロックを非同期に使用してみました。タイムアウトを 0 にすると、(sendSynchronousRequest への) 呼び出しは返されません。それ以外の場合はすべて、タイムアウトが発生し、WCF 呼び出し (POST 要求) の受信バイト部分が WCF によって完了されません。
確認しました
これが私のiOSコードです:
dispatch_queue_t myQ = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(myQ, ^{ // First Queue the parsing
@try {
//Generate endpoint url
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",appState.posPostingURL,serviceName]];
//Setup request
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:10.0];
NSString *authStr = [NSString stringWithFormat:@"%@:%@", @"xxxx", @"xxxx"];
NSString *authData = [NSString base64StringFromString:authStr];
NSString *authValue = [NSString stringWithFormat:@"Basic %@", authData];
[request setValue:authValue forHTTPHeaderField:@"Authorization"];
//Setup request headers
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"no-cache" forHTTPHeaderField:@"Cache-Control"];
[request setValue:[NSString stringWithFormat:@"%d", [dataBuffer length]] forHTTPHeaderField:@"Content-Length"];
// Put the request data in the request body
[request setHTTPBody: dataBuffer];
NSHTTPURLResponse *urlResponse = nil;
NSError *error = nil;
// and send to the server synchronously
serverData = [[NSURLConnection sendSynchronousRequest:request
returningResponse:&urlResponse
error:&error] mutableCopy];
// Now check the status and response
if (error) {
私のWCFコードは次のとおりです
namespace MyWebService{
[ServiceContract(Name = "MyServiceIntegrator", Namespace = "")]
public interface IMyIntegrator
{
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "/Configure",
BodyStyle=WebMessageBodyStyle.Bare,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
Result Configure(MyServerConfig config);
app.config ファイルでは、サービス エンドポイントが次のように構成されています。
binding="webHttpBinding"
トレース ビューは次のとおりです。
JSON が有効であるにもかかわらず、サーバーが読み取りを完了しない理由がいずれかの側にある可能性があります。
NSURLConnection JSON Submit to Serverも確認 しましたが、リクエストを送信するコードが正しいことがわかる限り。
任意のアイデア - 3 日前から髪を抜いています