今天在使用WCF调试时出现了以下异常
”无法处理消息。这很可能是因为操作“http://tempuri.org/IUserInfo/GetUserUserList”不正确,或因为消息包含无效或过期的安全上下文令牌,或因为绑定之间出现不匹配。如果由于未处于活动状态导致服务中止了该通道,则安全上下文令牌无效。若要防止服务永久中止闲置会话,请增加服务终结点绑定上的接收超时“
服务器端的配置如下
<system.serviceModel>
<!--测试配置-->
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IUserInfo"
maxBufferPoolSize="12000000" maxReceivedMessageSize="12000000" useDefaultWebProxy="false">
<readerQuotas maxStringContentLength="12000000" maxArrayLength="12000000"/>
<security mode="None"/>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="WCFMonitorInterface.UserInfoService">
<!-- Service Endpoints -->
<endpoint address="http://192.168.14.18:20005/UserInfoService/mex" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IUserInfo"
contract="WCFMonitorInterface.Interfaces.IUserInfo">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false -->
<serviceMetadata httpGetEnabled="true" httpGetUrl="http://192.168.14.18:20005/UserInfoService/metadata"/>
<!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
客户端配置如下
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IUserInfo"
maxBufferPoolSize="12000000" maxReceivedMessageSize="12000000" useDefaultWebProxy="false">
<readerQuotas maxStringContentLength="12000000" maxArrayLength="12000000"/>
<security mode="None"></security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://192.168.14.18:20005/UserInfoService"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IUserInfo"
contract="UserInfoService.IUserInfo" name="WSHttpBinding_IUserInfo">
<identity>
<userPrincipalName value="ludi\ODST" />
</identity>
</endpoint>
</client>
</system.serviceModel>
由于WCF服务是寄宿在一个控制台程序下,也做了一些初始设置,代码如下
host.AddServiceEndpoint(typeof(IUserInfo), new WSHttpBinding(), uri);
if (host.Description.Behaviors.Find<ServiceMetadataBehavior>() == null)
{
ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
behavior.HttpGetEnabled = true;
behavior.HttpGetUrl = new Uri(MetaUri);
host.Description.Behaviors.Add(behavior);
}
host.Opened += delegate
{
Console.WriteLine("WCF服务已开启");
Console.WriteLine("WCF服务元数据地址:"+MetaUri);
};
host.Open();
以上,望解答,谢谢