Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
安全WCF不适用于非windows客户端iPhone_Iphone_Ios_Wcf_Soap_Https - Fatal编程技术网

安全WCF不适用于非windows客户端iPhone

安全WCF不适用于非windows客户端iPhone,iphone,ios,wcf,soap,https,Iphone,Ios,Wcf,Soap,Https,我创建了WCFSOAP服务来处理我的iPhone应用程序。在VS中使用服务客户端“编码客户端”和WCF测试客户端工具可以很好地工作,但在iPhone、Java或PHP不起作用的情况下。 WCF在https配置上的工作 像这样装订 <bindings> <wsHttpBinding> <binding name="wsHttpEndpointBinding" maxBufferPoolSize="2147483647" maxReceivedM

我创建了WCFSOAP服务来处理我的iPhone应用程序。在VS中使用服务客户端“编码客户端”和WCF测试客户端工具可以很好地工作,但在iPhone、Java或PHP不起作用的情况下。 WCF在https配置上的工作

像这样装订

<bindings>
  <wsHttpBinding>
    <binding name="wsHttpEndpointBinding" maxBufferPoolSize="2147483647"
      maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" />
      <security mode="TransportWithMessageCredential">
        <transport clientCredentialType="None" />
        <message clientCredentialType="UserName" negotiateServiceCredential="false"
          establishSecurityContext="false" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host
{
    return YES; // Or whatever logic
}

+ (void)setAllowsAnyHTTPSCertificate:(BOOL)allow forHost:(NSString*)host 
{ 
}
要接受来自服务器的证书,请使用SOAP信封

NSString *soapMessage = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns=\"http://tempuri.org/\"><soap:Body><Authenticate><userid>username</userid><password>pass</password></Authenticate></soap:Body></soap:Envelope>"];
NSURLConnectionLegate

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    [webData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [webData appendData:data];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    NSLog(@"%@",[NSString stringWithFormat:@"Connection failed: %@", [error description]]);
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {

    NSLog(@"Data has been loaded");

    NSString *responseString = [[NSString alloc] initWithData:webData encoding:NSUTF8StringEncoding];


    NSLog(@"Respose Data :%@",responseString) ;


}

连接始终成功,但响应数据始终为空

您的soapMessage是错误的

你用错标签了

在soamMessage字符串中使用“Authenticate”标记而不是“test”标记

NSString *soapMessage = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns=\"http://tempuri.org/\"><soap:Body><Authenticate><userid>username</userid><password>pass</password></Authenticate></soap:Body></soap:Envelope>"];
NSURL *url = [NSURL URLWithString:@"https://mywebsite.com/Service/Service1.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: @"http://tempuri.org/IService1/Authenticate" forHTTPHeaderField:@"soapAction"];
    [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
    [NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]]; 
    [theRequest setHTTPMethod:@"POST"];     
    [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

    if(theConnection) {
        webData = [NSMutableData data] ;
    }
    else {
        NSLog(@"theConnection is NULL");
    }
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    [webData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [webData appendData:data];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    NSLog(@"%@",[NSString stringWithFormat:@"Connection failed: %@", [error description]]);
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {

    NSLog(@"Data has been loaded");

    NSString *responseString = [[NSString alloc] initWithData:webData encoding:NSUTF8StringEncoding];


    NSLog(@"Respose Data :%@",responseString) ;


}