gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 11:20:11 25 4
gpt4 key购买 nike

您好,我正在尝试在我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com