2009-11-01 61 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将失败,但不是真的说为什么。所以你可以最终追逐一个实际上并不存在的代码错误的幽灵。