2012-02-16 16 views
5

Hola Hice un servicio WCF alojado en el proyecto de Windows Azure como WebRole.Problema de enlace de seguridad WCF

Mi servicio está protegido con un certificado SSL y esto funciona.
Ahora quiero agregar algo de seguridad extra en mi contrato de operación y si lo hago (establezco un nivel de protección) obtengo el próximo error.

Necesito configurar algún enlace u otra cosa para hacer este trabajo, pero no sé qué y no sé dónde.

información

Proyecto:

error:

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/'). 

Arquitectura

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> 

Contrato

[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> 

Respuesta

3

Si establece su servicio como EncryptAndSign, se debe usar el transporte garantizado, por ejemplo, HTTPS. No sé en su última captura de pantalla si vio el servicio a través de HTTP o HTTPS, pero tiene que usar HTTPS.

Si desea que IIS se ocupe de la vinculación segura, puede configurar el modo de seguridad como TransportWithCredentialOnly y configurar su función web para usar su certificado para enlazar con 443, lo que creo que ya ha hecho, y luego deberia estar bien.

Alternativamente, puede usar la seguridad de transporte y en la parte ServerCredential necesita especificar qué certificado desea que use la WCF para crear el transporte seguro.

Nunca he intentado el modo de seguridad de mensajes, pero creo que debería funcionar, pero es posible que también deba especificar el certificado, bajo el elemento de configuración de seguridad del mensaje.

+0

No, todavía tengo la misma falla, pero supongo que estoy equivocado en mi arquitectura o configuración? ¿Ves mi estructura -> última captura de pantalla? ¿Debo configurar el enlace en web.config o en las configuraciones del proyecto de Azure? – dg90

+0

en su web.config. Voy a echar un vistazo cuando tenga tiempo y luego me pondré en contacto contigo. –

+0

Gracias sería genial, he vinculado muchas cosas, pero siempre sigue arrojando el mismo error, ya que no toma mi configuración o la configuro mal ...; – dg90