Безопасный WCF не работает с не-клиентами Windows - PullRequest
1 голос
/ 12 марта 2012

Я создаю сервис WCF SOAP для работы с моим приложением iPhone. Он отлично работает с инструментом «Клиент кодирования» и клиент WCF Test Client в VS, но с 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>

и поведение как:

<services>
      <service behaviorConfiguration="ServiceBehavior" name="HR_Service.Service">
        <endpoint address="mex" binding="mexHttpsBinding" bindingConfiguration=""
          name="MexHttpsBindingEndpoint" contract="HR_Service.IService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"
            httpsGetBinding="" />
          <serviceDebug includeExceptionDetailInFaults="false" />
          <dataContractSerializer maxItemsInObjectGraph="6553600" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

и совместимость сеансов ASP.net

<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="true" /> 

и мой айфон такой

+ (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>"];

тогда конверт

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");
    }

NSURLConnectionDelegate

- (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) ;


}

соединение всегда успешное, но данные ответа всегда пустые

1 Ответ

0 голосов
/ 12 марта 2012

Ваше мыльное сообщение неверно

вы используете неправильный тег

используйте тег "Authenticate" вместо тега "test" в soamMessage String

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...