LUDI901029
2015-07-30 14:45
采纳率: 100%
浏览 2.8k
已采纳

WCF客户端调用时出现”无法处理消息。这很可能是因为操作不正确“问题

今天在使用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();

以上,望解答,谢谢

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • threenewbee 2015-07-30 15:18
    已采纳
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题