【问题标题】:Why is my WCF wshttpbinding client doesn't work at another computer?为什么我的 WCF wshttpbinding 客户端在另一台计算机上不起作用?
【发布时间】:2014-08-01 06:47:17
【问题描述】:

首先,我在 winform 中托管我的 wcf 服务并尝试使用 wsHttpBinding。我的客户端应用程序仅在我的开发计算机中工作。为什么我的 WCF wshttpbinding 客户端在另一台计算机上不起作用?在另一台计算机上,当我执行服务时,它显示“调用者未经服务验证”

这是我的 WCF winform 主机配置(app.config):

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
    <connectionStrings>
      <add name="DBCS"
           connectionString="data source=localhost;DataBase=LatihanSP;Integrated Security=SSPI"
           providerName="System.Data.SqlClient" />
    </connectionStrings>
    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior name="XServerSvcBehavior">
                    <serviceDebug includeExceptionDetailInFaults="true" />
                    <serviceMetadata httpGetEnabled="true" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <services>
            <service behaviorConfiguration="XServerSvcBehavior" name="ServerTier.ServiceClient">
                <endpoint address="" binding="wsHttpBinding" bindingConfiguration=""
                    name="XServerSvcBasicHttpEndPoint" contract="ServerTier.IServiceClient" />
                <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
                    name="XServerSvcMexHttpEndPoint" contract="IMetadataExchange" />
                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost:7777/SampleSvc" />
                    </baseAddresses>
                </host>
            </service>
        </services>
    </system.serviceModel>
</configuration>

这是我的客户端 app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="XServerSvcBasicHttpEndPoint" />
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:7777/SampleSvc" binding="wsHttpBinding"
                bindingConfiguration="XServerSvcBasicHttpEndPoint" contract="ServiceRef.IServiceClient"
                name="XServerSvcBasicHttpEndPoint">
                <identity>
                    <userPrincipalName value="Kevin-EDP\Kevin" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>

我尝试将 userPrincipalName 值更改为计算机的名称,但我的客户端仍然无法工作,当我执行服务时,它显示“调用者未经服务验证” 我真的很确定我的代码可以正常工作,当我使用 basicHttpBinding 时,当我在互联网上查看一些解决方案时,大多数人建议使用 basicHttpBinding,但这不是我想要的答案,出于安全原因,我想使用 wsHttpBinding

帮帮我,我被困了将近 3 天,仍然无法弄清楚

【问题讨论】:

    标签: c# .net winforms wcf


    【解决方案1】:

    将安全模式设置为无。您可以在 WCF 服务配置文件中创建绑定配置元素

    <wsHttpBinding>
                    <binding name="XServerSvcBasicHttpEndPoint">
    <security mode="None"></security>
    </binding>
                </wsHttpBinding>
    

    并使用端点标签中的配置,如

    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="XServerSvcBasicHttpEndPoint"
                        name="XServerSvcBasicHttpEndPoint" contract="ServerTier.IServiceClient" />
    

    【讨论】:

    • 出于某种安全原因我需要安全模式,有什么办法让它工作吗?
    • 我认为对于 Windows 身份验证,服务和客户端必须在同一个域下。检查服务是否也在域 Kevin-EDP 下
    • 所以不能使用不在同一个域中的计算机? @patel 我的客户不会在同一个域中,因为我的 wcf 将通过互联网访问
    • 是的,我选择了这个答案,因为这种身份验证类型需要一台具有相同“域”的计算机,如果没有,它将无法工作..谢谢您的帮助
    【解决方案2】:

    在客户端部分将身份更改为以下格式 identity impersonate="true" userName="domain\user" password="password"/>

    【讨论】:

    • 设置安全模式为无,或消息安全模式为无
    • 我无法设置身份模拟,它说“不允许模拟属性”。如果我将消息安全性设置为无,它将与 basicHttpBinding 相同,对吗?然后消息没有加密..
    • 我的配置是 app.config,而不是 web.config,因为我使用 winform 作为 wcf 主机
    猜你喜欢
    • 2012-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-30
    • 1970-01-01
    • 1970-01-01
    • 2022-11-06
    相关资源
    最近更新 更多