所以我会第一个承认我对 WS-Security 内部原理知之甚少。我有一个 SOAP 服务工厂,如下所示。当将此服务与仅用于内部测试的 .NET 客户端(通过 svcutil.exe + 自动生成的 WSDL 使用自动生成的 .cs 代理类)一起使用时,一切正常。我可以在第 5 个“实际”(加密)SOAP 请求/响应之前看到前 4 个安全 SOAP 请求-响应握手对。我一般了解安全性,但希望我知道有关此特定握手的详细信息-我猜他们正在执行 key 交换?
无论如何,部分原因是
我在想我应该通过 HTTPS + HTTP 基本身份验证进行 SOAP 交换。 所以问题归结为
public class SoapServiceHostFactory : ServiceHostFactory
{
private Type serviceInterfaceType;
public SoapServiceHostFactory(Type serviceInterfaceType)
{
this.serviceInterfaceType = serviceInterfaceType;
}
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
ServiceHost host = base.CreateServiceHost(serviceType, baseAddresses);
ServiceMetadataBehavior smb = host.Description.Behaviors.Find<ServiceMetadataBehavior>();
// Enable metadata
if (smb == null)
{
smb = new ServiceMetadataBehavior();
host.Description.Behaviors.Add(smb);
}
smb.HttpGetEnabled = true;
// Enable debugging for service
ServiceDebugBehavior sdb = host.Description.Behaviors.Find<ServiceDebugBehavior>();
if (sdb == null)
{
sdb = new ServiceDebugBehavior();
host.Description.Behaviors.Add(sdb);
}
sdb.IncludeExceptionDetailInFaults = true;
// SOAP Security configuration
WSHttpBinding myBinding = new WSHttpBinding();
myBinding.Security.Mode = SecurityMode.Transport;
host.AddServiceEndpoint(serviceInterfaceType, myBinding, "");
return host;
}
}
最佳答案
您会发现 SSL + 基本身份验证比 WS-Security 更具互操作性。
如果您只是在进行点对点集成,那么 SSL 肯定是可行的方法,如果您有更复杂的多跳、多方集成,那么您可能需要使用 WS-Security 来解决这个问题。
关于SOAP 1.2 通过 SSL + HTTP 基本身份验证还是 WS-Security?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9542604/