2012-02-16 210 views
5

您好我做在Windows Azure項目託管作爲WebRole一個WCF服務。WCF安全綁定問題

我的服務固定與SSL證書和工作原理。
現在我想爲我的操作合同添加一些額外的安全性,如果我這樣做(設置保護級別),我會得到下一個錯誤。

我需要配置一些綁定或其他東西來獲得這項工作,但我不知道什麼,我不知道在哪裏。

項目信息:

錯誤:

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

架構

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> 

合同

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

回答

3

如果您的服務設置爲EncryptAndSign,它必須使用安全的交通,例如HTTPS。如果您通過HTTP或HTTPS查看服務,則不知道您的上一個屏幕截圖,但您必須使用HTTPS。

如果您希望IIS注意安全綁定,您可以將安全模式設置爲TransportWithCredentialOnly,並將Web角色配置爲使用您的證書綁定到443,我認爲您已經完成了該操作,然後它應該是可以的。

或者您可以使用運輸的安全,並在ServerCredential部分需要指定你想要的WCF用來創建安全運輸的證書。

我從來沒有嘗試過的信息安全模式,但我認爲它應該工作,但是你可能需要指定證書以及,消息安全配置元素。

+0

不,我還是得到了同樣的錯誤,但我想我錯了,在我的體系結構或配置?你看到我的結構 - >最後截圖。我是否必須在web.config或Azure項目配置中配置綁定? – dg90 2012-02-17 07:14:21

+0

在你的web.config中。當我有空時,我會看看,然後回到你身邊。 – 2012-02-17 08:07:10

+0

謝謝你會很棒,我綁了很多東西,但它總是不斷拋出相同的錯誤,就像他不採取我的配置或我配置錯誤..; – dg90 2012-02-17 08:17:29