简体   繁体   English

使用BasicHttpBinding和Windows身份验证使用WCF服务

[英]Consuming WCF Service with BasicHttpBinding and Windows Authentication

I have a WCF service with the following binding: 我有一个带有以下绑定的WCF服务:

<basicHttpBinding>        
  <binding name="bind" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
     <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
        <message algorithmSuite="Default" clientCredentialType="UserName"/>
     </security>
  </binding>
</basicHttpBinding>

I am consuming it dynamically in code with this endpoint: 我在使用此端点的代码中动态使用它:

BasicHttpBinding binding = new BasicHttpBinding();
binding.Name = "bind";
binding.MaxBufferSize = int.MaxValue;
binding.MaxReceivedMessageSize = int.MaxValue;
ServiceEndpoint endPoint = new ServiceEndpoint(ContractDescription.GetContract(typeof(ImyContract)), binding, new EndpointAddress(endPointAddress));

endPoint.Name = name;
ChannelFactory<ImyContract> channelFactory = new ChannelFactory<ImyContract>(endPoint);

When I browse to the service everything works exactly as expected, however when connecting through the application I get: 当我浏览到该服务时,一切都按预期完成,但是当通过应用程序连接时,我得到:

Content Type text/xml; 内容类型text / xml; charset=utf-8 was not supported by service http://localhost/SynchronizationService/SyncService.svc/DataBinding . 服务http://localhost/SynchronizationService/SyncService.svc/DataBinding不支持charset = utf-8。 The client and service bindings may be mismatched. 客户端和服务绑定可能不匹配。

I understand this error is caused often because basicHttpBinding using SOAP 1.1 and wsHttpBinding uses 1.2, however, I am not using SSL on the server, and have another endpoint using streaming, so switching is not an option for me. 我理解这个错误经常是因为使用SOAP 1.1和wsHttpBinding的basicHttpBinding使用1.2,但是,我没有在服务器上使用SSL,并且有另一个端点使用流,所以切换不是我的选择。 What am I doing wrong that is prevening me from consuming the service correctly? 我做错了什么阻止我正确使用服务?

UPDATE: 更新:

Also, I am not using the default basicHttpBinding on the client, but setting security to match what the server is expecting. 此外,我没有在客户端上使用默认的basicHttpBinding,而是设置安全性以匹配服务器的期望。 I am setting the security with this method: 我用这种方法设置安全性:

private static BasicHttpSecurity SetEndpointSecurity()
{
    BasicHttpSecurity security = new BasicHttpSecurity();
    HttpTransportSecurity transport = new HttpTransportSecurity();
    BasicHttpMessageSecurity message = new BasicHttpMessageSecurity();

    security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;

    transport.ClientCredentialType = HttpClientCredentialType.Windows;
    transport.ProxyCredentialType = HttpProxyCredentialType.None;
    transport.Realm = "";

    message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
    message.AlgorithmSuite = System.ServiceModel.Security.SecurityAlgorithmSuite.Default;

    security.Transport = transport;
    security.Message = message;

    return security;
}

Thanks the_ajp for your suggestion to let .NET build the proxy class and then re-implement its endpoint's in code as this led me to the correct solution! 感谢the_ajp的建议让.NET构建代理类,然后在代码中重新实现其端点,因为这导致我找到了正确的解决方案!

As it turns out, my attempts to resolve the error "The client and service bindings may be mismatched.", led me to make the client and server endpoint bindings TOO similar. 事实证明,我试图解决错误“客户端和服务绑定可能不匹配。”,导致我使客户端和服务器端点绑定TOO类似。 The key was to explicitly specify the TextEncoding as UTF-8 on the client endpoint and to utilize wsHttpBinding on the client, even though I was connecting to a basicHttpBinding on the server. 关键是在客户端端点上明确指定TextEncoding为UTF-8,并在客户端上使用wsHttpBinding,即使我连接到服务器上的basicHttpBinding。 This kept the message in SOAP 1.2 all the way from origin to destination, without requiring setting up SSL security on the server. 这使得消息在SOAP 1.2中始终从始发地到目的地,而不需要在服务器上设置SSL安全性。

Thanks for all your help getting to the right solution guys! 感谢您帮助我们找到合适的解决方案!

Kris C, hopefully this can be of use to you in what you are working on next :)! Kris C,希望这对你下一步的工作有用:)!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用basicHttpBinding和Windows身份验证以及二进制编码配置WCF服务 - How to configure a WCF service with basicHttpBinding and windows authentication and binary encoding Windows 8.1 WCF客户端无法通过BasicHttpBinding通过摘要身份验证连接到服务 - Windows 8.1 WCF client fails to connect to service with digest authentication over BasicHttpBinding WCF服务的basicHttpBinding上的HTTPS - HTTPS on basicHttpBinding for WCF Service 基本HttpBinding的WCF服务配置 - WCF Service Configuration for basicHttpBinding 使用WCF消费REST服务-基本身份验证 - Consuming REST Service with WCF - Basic Authentication 如果我在Windows服务中运行basicHttpBinding WCF终结点,我需要安装哪些Windows功能? - If I run a basicHttpBinding WCF endpoint in a windows service what windows features do I need to install? 通过带有用户名身份验证的SSL的经典ASP消费WCF服务 - Classic ASP Consuming WCF Service through SSL with UserName Authentication 查找Windows服务托管的WCF basicHttpBinding端点每分钟的高峰请求 - Find peak requests per minute, Windows Service-hosted WCF basicHttpBinding endpoint Windows Phone错误处理:具有BasicHttpBinding和TransportWithMessageCredential的WCF - Windows Phone Error Handling: WCF with BasicHttpBinding and TransportWithMessageCredential 消耗WCF Web服务 - Consuming WCF Web Service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM