wcf 服务 c# .net 框架 4.5.1

wcf service c# .net framework 4.5.1

我在 winform 上托管了一个 wcf 服务,当我在本地(同一服务器)调用该服务时它运行良好,但是客户端不同的 IP(同一域)它抛出了一个异常: 无法处理该消息。这很可能是因为操作 'http://tempuri.org/ICenterService/SaveCoursesIntoAllDevices' 不正确,或者因为消息包含无效或过期的安全上下文令牌,或者因为绑定之间存在不匹配。如果服务由于不活动而中止通道,则安全上下文令牌将无效。为防止服务过早地中止空闲会话,增加服务端点绑定的接收超时。

请帮帮我 谢谢

服务器站点:

        <wsHttpBinding>
            <binding name="WSHttpBinding_ICenterService" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false" maxReceivedMessageSize="2147483647" maxBufferPoolSize="1024768">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession enabled="true" />
                <security mode="None">
                    <transport clientCredentialType="None" />
                    <message clientCredentialType="None" negotiateServiceCredential="false" establishSecurityContext="false" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <services>
        <service behaviorConfiguration="CenterServer.Services.CenterServiceBehavior" name="Ecotek.Communication.HostWebService.CenterService">
            <host>
                <baseAddresses>
                    <add baseAddress="http://192.168.1.129:6085/SyncServices" />
                </baseAddresses>
            </host>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
            <endpoint address="" binding="wsHttpBinding" contract="Ecotek.Communication.HostWebService.ICenterService">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
        </service>
    </services>

根据你提供的配置文件,我发现你没有应用WSHttpBinding_ICenterService到endpoint.This可能是错误的原因,因为如果你使用wsHttpBinding和客户端和服务器不在同一台电脑上,需要设置security mode="None".

<services>
            <service behaviorConfiguration="CenterServer.Services.CenterServiceBehavior" name="Ecotek.Communication.HostWebService.CenterService">
                <host>
                    <baseAddresses>
                        <add baseAddress="http://192.168.1.129:6085/SyncServices" />
                    </baseAddresses>
                </host>
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
                <endpoint address="" binding="wsHttpBinding" contract="Ecotek.Communication.HostWebService.ICenterService" bindingConfiguration="WSHttpBinding_ICenterService">
                    <identity>
                        <dns value="localhost" />
                    </identity>
                </endpoint>
            </service>
        </services>

您需要将绑定配置应用到端点。