【问题标题】:Security/authorization on consuming WCF service使用 WCF 服务的安全/授权
【发布时间】:2014-09-07 19:57:36
【问题描述】:

我对 WCF 有点陌生。我创建了一个服务并且它有效。该服务在 XML 字符串中接收一些请求的键,并返回一个 XML 结果集。

这是我的一般性问题,然后我会给出一些细节。如果有人使用wsHttpBinding 在 WCF 中创建 RESTful 服务,是否有人从外部使用该服务需要提供用户名/PW 凭据?

好的,详细信息。在服务器端,这是核心配置:

<services>
    <service behaviorConfiguration="MyService1Behavior"  name="MyRestService">
        <endpoint 
            address="http://(address)/myweb/myrestservice.svc"  
            binding="wsHttpBinding"  
            contract="IMyRestService">
          <identity> <dns value="numeric address" />  </identity> 
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    </service>
</services>

和服务应用接口:

[ServiceContract]
public interface IMyRestService
{
    [OperationContract]
    [WebInvoke(Method = "GET",
     ResponseFormat = WebMessageFormat.Xml,
     BodyStyle = WebMessageBodyStyle.Wrapped,
     UriTemplate = "OrderLookup/{LookupData}")]
    string OrderLookup(string LookupData);
}

就像我说的,当我从完全在域外的系统中使用它时,这一切都有效。

但我必须提供凭据,如下所示:

MyClientService.ClientCredentials.Windows.ClientCredential.Domain = "remoteserver";
MyClientService.ClientCredentials.Windows.ClientCredential.UserName = "UserID";
MyClientService.ClientCredentials.Windows.ClientCredential.Password = "Password";

我有点担心尝试使用非 .NET 客户端使用服务的人不想提供凭据。所以 - 如果我使用 WCF 创建了一个 RESTful 服务并将其托管在 IIS 上......是否有人从外部访问该服务需要提供凭据,或者有没有办法可以安全地提出不同的解决方案?

再次,我意识到我的知识存在差距 - 只是想填补它们。

提前感谢您的任何建议......

【问题讨论】:

  • wsHttpBinding 不是 RESTful 绑定——它是SOAP。使该服务成为 REST 服务的唯一绑定是 webHttpBinding

标签: .net wcf rest authorization credentials


【解决方案1】:

正如 Marc 在他的评论中所说,可以说您实现的并不是真正的 RESTful 服务,而是一种基于 SOAP 1.2 的 POX 服务。

但是,由于您使用的是 wsHttpBinding,因此您可以确信服务和消费者之间的任何流量都将受到此绑定堆栈的 standard security settings 的限制,而后者又实现了 WS-Security soap 扩展。

这实际上意味着不仅非 .net 消费者会受到保护,他们也可能会受到struggle to consume this endpoint 的保护,因为 wsHttpBinding 的默认设置对于互操作性不是很开放(例如,默认情况下它使用 Windows 身份验证,因为你已经在上面找到了)。

如果您需要支持非 .net 客户端,请使用使用 SOAP 1.1 的 basicHttpBinding。如果这是您的要求,您可以使用 SSL 和用户名/密码或证书still secure these endpoints

【讨论】:

    猜你喜欢
    • 2010-10-31
    • 2011-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-24
    • 2020-04-17
    • 1970-01-01
    相关资源
    最近更新 更多