2012-02-16 14 views
5

Witam Wykonałem usługę WCF hostowaną w projekcie Windows Azure pod nazwą WebRole.Problem wiązania zabezpieczeń WCF

Moja usługa jest zabezpieczona certyfikatem SSL i to działa.
Teraz chcę dodać dodatkowe zabezpieczenie na mojej umowie o operację, a jeśli to zrobię (ustawi poziom ochrony), otrzymam następny błąd.

Potrzebuję skonfigurować niektóre wiązania lub coś innego, aby uzyskać tę pracę, ale nie wiem co i nie wiem gdzie.

informacji

Projekt:

Błąd:

The request message must be protected. This is required by an operation of the contract ('IService1','http://tempuri.org/'). 
    The protection must be provided by the binding ('BasicHttpBinding','http://tempuri.org/'). 

Architektura

enter image description here
ServiceConfiguration.Cloud.cscfg & ServiceConfiguration.Local.cscfg

<?xml version="1.0" encoding="utf-8"?> 
<ServiceConfiguration serviceName="Azure" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="1" osVersion="*"> 
    <Role name="WCFServiceWebRole"> 
    <Instances count="1" /> 
    <ConfigurationSettings> 
     <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" /> 
    </ConfigurationSettings> 
    <Certificates> 
     <Certificate name="Certificate1" thumbprint="51F357715F" thumbprintAlgorithm="sha1" /> 
    </Certificates> 
    </Role> 
</ServiceConfiguration> 

ServiceDefinition.csdef

<?xml version="1.0" encoding="utf-8"?> 
<ServiceDefinition name="Azure" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition"> 
    <WebRole name="WCFServiceWebRole" vmsize="ExtraSmall" enableNativeCodeExecution="true"> 
    <Sites> 
     <Site name="Web"> 
     <Bindings> 
      <Binding name="Endpoint1" endpointName="Endpoint1" /> 
      <Binding name="Endpoint2" endpointName="Endpoint2" /> 
     </Bindings> 
     </Site> 
    </Sites> 
    <Endpoints> 
     <InputEndpoint name="Endpoint1" protocol="http" port="80" /> 
     <InputEndpoint name="Endpoint2" protocol="https" port="8080" certificate="Certificate1" /> 
    </Endpoints> 
    <Imports> 
     <Import moduleName="Diagnostics" /> 
    </Imports> 
    <LocalResources> 
     <LocalStorage name="WCFServiceWebRole.svclog" sizeInMB="1000" cleanOnRoleRecycle="false" /> 
    </LocalResources> 
    <Certificates> 
     <Certificate name="Certificate1" storeLocation="LocalMachine" storeName="My" /> 
    </Certificates> 
    </WebRole> 
</ServiceDefinition> 

zamówieniu

[DataContract] 
public class KlantenContract 
{ 
    [DataMember] 
    public int PARTYID { get; set; } 

    [DataMember] 
    public string firstName { get; set; } 

    [DataMember] 
    public string lastName { get; set; } 

IService1.cs

namespace WCFServiceWebRole 
{ 
    [ServiceContract(ProtectionLevel = ProtectionLevel.EncryptAndSign)] 
    public interface IService1 
    { 
     [OperationContract(ProtectionLevel = ProtectionLevel.EncryptAndSign)] 
     List<KlantenContract> GetAllKlanten(string firstName); 
    } 
} 

Web.config

<system.serviceModel> 

    <bindings> 
     <wsHttpBinding> 
     <binding name="IService1"> 
      <security mode="Transport"></security> 
     </binding> 
     <binding name="Certificate1"> 
      <security> 
      <message clientCredentialType="Certificate"/> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 

    <services> 
     <service name="Service1" behaviorConfiguration="ServiceBehavior"> 
     <endpoint address="https://127.0.0.1:8080/Service1.svc" binding="wsHttpBinding" 
      name="Endpoint2" contract="IService1"> 
     </endpoint> 
     </service> 
    </services> 

    <behaviors> 
     <serviceBehaviors> 

      <behavior name="ServiceBehavior"> 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
      <serviceCredentials> 
       <serviceCertificate findValue="CN=tempCert" /> 
      </serviceCredentials> 
      </behavior> 

      <behavior> 
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> 
      <serviceMetadata httpGetEnabled="true" /> 
      <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 

Odpowiedz

3

Jeśli ustawisz swoje usługi jako EncryptAndSign, musi korzystać z transportu zabezpieczone, na przykład protokołu HTTPS. Nie wiem na ostatnim zrzucie ekranu, jeśli przeglądałeś usługę za pośrednictwem protokołu HTTP lub HTTPS, ale musisz korzystać z HTTPS.

Jeśli chciał IIS dbać jeśli zabezpieczone wiązania, można po prostu ustawić tryb zabezpieczeń na TransportWithCredentialOnly i skonfigurowaniu roli internetową, aby używać certyfikatu wiąże się z 443, które myślę, że zrobili już, a następnie powinno być ok.

Alternatywnie można użyć zabezpieczenia Transport, aw części ServerCredential trzeba określić, który certyfikat ma być używany przez WCF do utworzenia zabezpieczonego transportu.

Nigdy nie próbowałem trybu zabezpieczeń wiadomości, ale myślę, że powinien zadziałać, ale być może trzeba będzie również określić certyfikat, pod elementem konfiguracji bezpieczeństwa komunikatu.

+0

Nie, wciąż mam tę samą wadę, ale myślę, że jestem w błędzie w mojej architekturze lub konfiguracji? Czy widzisz moją strukturę -> ostatni zrzut ekranu. czy muszę skonfigurować powiązanie w pliku web.config lub w konfiguracji projektu Azure? – dg90

+0

W swoim pliku web.config. Będę miał czas, kiedy będę miał czas, a następnie wrócę do ciebie. –

+0

Dzięki, byłoby świetnie, wiązałem wiele rzeczy, ale zawsze wyrzuca mi ten sam błąd, ponieważ nie przyjmuje mojej konfiguracji lub konfiguruję ją źle.; – dg90

Powiązane problemy