2009-11-01 60 views
4

我已經花了前一週試​​圖獲得一個安全的WCF形式在Azure上工作,但都無濟於事!我的用例非常簡單。我想在雲中調用WCF端點並將消息傳遞給工作人員角色排隊。除此之外,我想限制訪問預先驗證的用戶,通過用戶名&密碼進行身份驗證。WCF + Azure =夢魘!

我試圖讓這與傳輸,TransportWithMessageCredential和消息安全工作,但似乎沒有工作。事實上,我已經完成了我可以找到的每個示例和代碼片段,最近的是http://code.msdn.microsoft.com/wcfazure頁面上的「使用帶有傳輸安全性和消息憑證的二進制HTTP綁定服務以及Silverlight客戶端」示例。我很確定我正在被小錯誤和beta變化所打倒,但最終的結果是我完全被卡住了。

這是我的一個關鍵路徑項目,所以任何建議將不勝感激。一個完整的工作示例或演練將會更好!

+2

如果您可以添加有關您遇到的特定問題的詳細信息,那麼任何人都會回答您的問題。現在,這本身並不是一個問題。 – 2009-11-01 22:12:44

+0

對不起,缺乏細節!基本上,我想要一個WinGUI應用程序可以調用的安全服務來將交易和其他相關的「任務」發佈到Azure隊列中。所有的任務都是無國籍和冪等的。幾十個用戶都需要將憑據傳遞給服務才能進行身份驗證和授權。至於安全模式,我更喜歡消息安全性,但也可以使用TranportWithMessageCredential安全性。除了那些我願意使用.NET服務總線的人,還沒有得到一個適合我的例子。 – 2009-11-02 13:39:37

+0

您是否正在尋找僅使用用戶名和密碼進行WCF呼叫的身份驗證? – BozoJoe 2012-01-25 00:32:38

回答

2

我遇到了很多的問題通過用戶名和密碼保護我的Web服務。我最終選擇通過證書的消息安全,它似乎更容易實現。 Step by step message security WCF

+0

亞倫,你是否在Azure雲上部署了這個?或者這是一個普通的vanila WCF安全端點,帶有證書? – Sentient 2011-05-16 19:37:30

+0

這是WCF Azure服務。 – Aaron 2011-06-01 23:16:37

0

我只知道如何做到這一點與匿名用戶,但也許我的設置將幫助你弄清楚。我知道下面的代碼可以與匿名用戶一起工作,也許你可以擺弄它以使其與認證一起工作。另外,保護Web端點的唯一方法是使用傳輸安全性通過HTTPS公開它(來源:http://msdn.microsoft.com/en-us/library/aa702697.aspx)。

的web.config

<system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name=""> 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" /> 
    </system.serviceModel> 

Inferface

IExample.cs:

using System.ServiceModel; 
using System.ServiceModel.Web; 

namespace WebPages.Interfaces 
{ 
    [ServiceContract] 
    public interface IExample 
    { 
     [OperationContract] 
     [WebInvoke(Method = "GET", 
      ResponseFormat = WebMessageFormat.Json)] 
     string GetSomething(string id); 
    } 
} 

ExampleService.svc.cs標記

<%@ ServiceHost Language="C#" Debug="true" Service="WebPages.Interfaces.ExampleService" CodeBehind="ExampleService.svc.cs" Factory="System.ServiceModel.Activation.WebServiceHostFactory" %> 

ExampleService.svc.cs代碼隱藏

namespace WebPages.Interfaces 
{ 
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
    public class ExampleService : IExample 
    { 
     string JsonSerializeSomething(Something something) 
     { 
      var serializer = new DataContractJsonSerializer(something.GetType()); 
      var memoryStream = new MemoryStream(); 

      serializer.WriteObject(memoryStream, something); 

      return Encoding.Default.GetString(memoryStream.ToArray()); 
     } 

     public string GetSomething(string id) 
     { 
      var something = DoSomeBusinessLogic(id); 

      return JsonSerializeSomething(something); 
     } 
    } 
} 

從客戶jQuery的通話

function _callServiceInterface(id, delegate) { 
    var restApiCall = "Interfaces/ExampleService.svc/GetSomething?id=" 
      + escape(id); 

    $.getJSON(restApiCall, delegate); 
} 

function _getSomethingFromService() { 
    _callServiceInterface('123', 
     function (result) { 
      var parsedResult = $.parseJSON(result); 
      $('#info').html(result.SomethingReturnedFromServiceCall); 
     } 
    ); 
} 
0

老問題,我不是完全肯定您的解決方案失敗,但據我理解你需要來自公認的可信來源的數字證書,而不僅僅是私人創建的證書才能使WCF與Azure一起工作。

如果你不使用一個,那麼據我瞭解,WCF將失敗,但不是真的說爲什麼。所以你可以最終追逐一個實際上並不存在的代碼錯誤的幽靈。