尝试从 WinForms 访问 WCF 服务时出现 MessageSecurityException [英] MessageSecurityException when trying to access WCF service from WinForms
问题描述
我有一个 WinForms 应用程序,它使用托管在远程服务器上的 WCF 服务.当我运行应用程序时,它会运行并加载数据,但在运行 30 秒或更长时间后,它会显示以下 MessageSecurityException
:
I have a WinForms application that consumes a WCF service hosted on remote server. When I run the application, it runs and loads data, but after 30 seconds or more of the running it shows following MessageSecurityException
:
安全处理器无法在信息.这可能是因为消息是不安全的故障或因为通信双方之间存在约束不匹配.如果为安全配置服务并且客户端没有使用安全性.
Security processor was unable to find a security header in the message. This might be because the message is an unsecured fault or because there is a binding mismatch between the communicating parties. This can occur if the service is configured for security and the client is not using security.
我的服务配置是:
<system.serviceModel>
<!-- change -->
<bindings>
<customBinding>
<binding name="Wrabind" closeTimeout="00:05:00" openTimeout="00:05:00" sendTimeout="00:25:00">
<textMessageEncoding/>
<security authenticationMode="SecureConversation" includeTimestamp="true" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
<localClientSettings maxClockSkew="00:30:00" />
<localServiceSettings maxClockSkew="00:30:00" />
<secureConversationBootstrap messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
<localClientSettings maxClockSkew="00:30:00" />
<localServiceSettings maxClockSkew="00:30:00" />
</secureConversationBootstrap>
</security>
<httpTransport maxBufferPoolSize="20000000" maxReceivedMessageSize="20000000" allowCookies="true" maxBufferSize="20000000" keepAliveEnabled="false" />
</binding>
</customBinding>
</bindings>
<!-- change -->
<services>
<service behaviorConfiguration="WServiceCoreService.Service1Behavior" name="WServiceCoreService.Service1">
<endpoint address="http://subdomain.domain.com/service1.svc" binding="customBinding" bindingConfiguration="Wrabind" contract="WServiceCoreService.IService1" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WServiceCoreService.Service1Behavior">
<serviceThrottling
maxConcurrentCalls="200"
maxConcurrentSessions="200"
maxConcurrentInstances="200" />
<!-- To avoid disclosing metadata information, set the value below to false before deployment -->
<serviceMetadata httpGetEnabled="false" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://subdomain.domain.com/" />
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
</system.serviceModel>
我的 WinForms 客户端配置是:
My WinForms Client Config is:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="CustomBinding_IService1" maxBufferPoolSize="20000000" maxReceivedMessageSize="20000000" allowCookies="true" closeTimeout="00:05:00" openTimeout="00:05:00" sendTimeout="00:25:00">
<readerQuotas maxDepth="32" maxStringContentLength="5242880" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://subdomain.domain.com/service1.svc" binding="wsHttpBinding"
bindingConfiguration="CustomBinding_IService1" contract="WCoreService.IService1"
name="CustomBinding_IService1">
<identity>
<userPrincipalName value="WIN-489ESBTC0A0\servewranglein_web" />
</identity>
</endpoint>
</client>
</system.serviceModel>
我无法预测此配置有什么错误.请尽快帮我解决这个问题.
I am unable to predict what is the error with this configuration. Please help me to solve this as soon as possible.
更新:我使用的是 .NET 4.0
UPDATE: I am using .NET 4.0
推荐答案
在我的例子中,在主机配置文件的 AudienceUris 标签中添加服务解决了同样的异常问题.
In my case adding the service in a audienceUris tag in the host config file fixed the issue with the same exception.
<system.identityModel>
...
<identityConfiguration>
...
<audienceUris>
<add value="serviceName.svc" />
</audienceUris>
...
</identityConfiguration>
...
</system.identityModel>
这篇关于尝试从 WinForms 访问 WCF 服务时出现 MessageSecurityException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!