当前位置: 代码迷 >> Web Service >> 急救:请问WCF的一些有关问题: 无法处理消息。这很可能是因为操作XXXX不正确!
  详细解决方案

急救:请问WCF的一些有关问题: 无法处理消息。这很可能是因为操作XXXX不正确!

热度:238   发布时间:2016-05-02 02:53:36.0
急救:请教WCF的一些问题: 无法处理消息。这很可能是因为操作XXXX不正确!!
程序的错误是这样的:
System.ServiceModel.FaultException: 无法处理消息。这很可能是因为操作“http://tempuri.org/IUser/AddUserModel”不正确,或因为消息包含无效或过期的安全上下文令牌,或因为绑定之间出现不匹配。如果由于未处于活动状态导致服务中止了该通道,则安全上下文令牌无效。若要防止服务永久中止闲置会话,请增加服务终结点绑定上的接收超时。

WCF的config文件配置:
C# code
<system.serviceModel>    <services>      <service behaviorConfiguration="WCFUser.UserBehavior" name="WCFUser.User">        <host>          <baseAddresses>            <add baseAddress="http://192.168.1.120:7766/User"/>          </baseAddresses>        </host>        <endpoint address="" binding="wsHttpBinding" contract="WCFUser.IUser">          <identity>            <dns value="192.168.1.120" />          </identity>                  </endpoint>        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />      </service>    </services>    <behaviors>      <serviceBehaviors>        <behavior name="WCFUser.UserBehavior">          <!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点-->          <serviceMetadata httpGetEnabled="true"/>          <!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息-->          <serviceDebug includeExceptionDetailInFaults="false"/>        </behavior>      </serviceBehaviors>    </behaviors>  </system.serviceModel>


由于是在调试阶段,我的宿主程序是控制台程序,app.config
C# code
<system.serviceModel>    <services>      <service name="WCFUser.User" behaviorConfiguration="WCFUser.UserBehavior">        <host>          <baseAddresses>            <add baseAddress="http://192.168.1.120:7766/User" />          </baseAddresses>        </host>        <endpoint address="" binding="wsHttpBinding" contract="WCFUser.IUser">          <identity>            <dns value="192.168.1.120"/>          </identity>        </endpoint>        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />      </service>    </services>    <behaviors>      <serviceBehaviors>        <behavior name="WCFUser.UserBehavior">          <!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点-->          <serviceMetadata httpGetEnabled="true"/>          <!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息-->          <serviceDebug includeExceptionDetailInFaults="false"/>        </behavior>      </serviceBehaviors>    </behaviors>  </system.serviceModel>


WEB网页web.config客户端配置:
C# code
<system.serviceModel>        <bindings>            <wsHttpBinding>                <binding name="WSHttpBinding_IUser" closeTimeout="00:01:00" openTimeout="00:01:00"                    receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"                    transactionFlow="false" hostNameComparisonMode="StrongWildcard"                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"                    allowCookies="false">                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />                    <reliableSession ordered="true" inactivityTimeout="00:10:00"                        enabled="false" />                    <security mode="None">                        <transport clientCredentialType="Windows" proxyCredentialType="None"                            realm="" />                        <message clientCredentialType="Windows" negotiateServiceCredential="true"                            algorithmSuite="Default" establishSecurityContext="true" />                    </security>                </binding>            </wsHttpBinding>        </bindings>        <client>            <endpoint address="http://192.168.1.120:7766/User" binding="wsHttpBinding"                bindingConfiguration="WSHttpBinding_IUser" contract="WCFService.IUser"                name="WSHttpBinding_IUser">                <identity>                    <dns value="192.168.1.120" />                </identity>            </endpoint>        </client>    </system.serviceModel>
  相关解决方案