c# - WCF 中的消息无法处理异常

标签 c# .net wcf service

您好,我正在尝试在我的 Windows 应用程序中调用 WCF 服务

我将服务引用添加到我的项目中,但在执行时出现以下错误:

This is most likely because the action 'http://tempuri.org/IUser/SaveUser' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.

我尝试增加服务端点绑定(bind)的接收超时。但同样的异常(exception)也在那里。

这是客户端的配置文件

<configuration>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IUser" closeTimeout="00:01:00" openTimeout="00:01:00"
                    receiveTimeout="00:30: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:45:00"
                        enabled="false" />
                  <security mode="None">
                    <transport clientCredentialType="None" />
                  </security>

                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://t2.ipixsolutions.net/Service.svc" binding="wsHttpBinding"
                bindingConfiguration="WSHttpBinding_IUser" contract="ServiceReference1.IUser"
                name="WSHttpBinding_IUser">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>

在服务器端配置

<system.serviceModel>
        <services>
      <service behaviorConfiguration="ServiceBehavior" name="WCFLibrary.Users">
                <endpoint address="" binding="wsHttpBinding" contract="WCFLibrary.IUser">
          <identity>
                        <dns value="localhost"/>
                    </identity>
                </endpoint>
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="ServiceBehavior">
                    <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                    <serviceMetadata httpGetEnabled="true"/>
                    <!-- 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="false"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>

最佳答案

嘿,我遇到了同样的异常,在我的例子中,这是因为这个设置:

<security mode="None">

如果我把它改成:

<security mode="Message">

它工作正常。我想它必须从默认值中获取,因为我没有在服务器端设置它。

关于c# - WCF 中的消息无法处理异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11288389/

相关文章:

C#:DateTimePicker 在使用自定义格式的低宽度程序启动时有下拉显示错误。是什么原因造成的?

c# - 使用 Linq 基于逗号分隔的属性值拆分 List<T>

c# - 可以使用通配符指定目录路径吗?

c# - 在代理客户端中获取 SOAP 请求体

c# - 操作对于 LINQ to SQL ExecuteCommand 事务的状态无效

c# - Firebase Unity 密码身份验证失败

c# - python/C++/C#/Java 中两个句子之间的相关性?

.NET:向同一应用程序的所有实例发送文本消息并阅读

.net - 禁用交换(页面文件)以确保所有内容都在内存中

wcf - WCF数据服务-如何诊断请求错误?