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

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
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!