3

我和我的团队正在开发一个相当大的应用程序,其中包含许多基于 WCF NetTCP 的服务。此系统将在其下运行的 Windows 服务不是本地帐户,而是标准域用户(在托管服务的服务器上具有管理员权限)。在测试连接性的过程中,我遇到了 SSPI 调用失败的问题。基于几个小时的研究,这导致我在客户端配置中丢失了以下行:

<identity>
     <userPrincipalName value="MACHINE\user" />
</identity>

使用它的问题是我不使用 VS 或 svcutil 为该服务生成客户端/代理 - 正在使用的代理完全用代码编写,并且它们继承 System.ServiceModel.ClientBase。我相信选择此选项的最初原因是我们可以使用完全相同的 DataMember 对象,这些对象通过围栏两侧的服务 - 第三方组不需要连接到我们的服务,所以这不是问题.

当我没有在标准 system.serviceModel 配置部分指定端点时,有谁知道我在客户端(代码或通过配置)中设置 userPrincipalName 的方法?

这是我的客户端 web.config 的外观以供参考:

    <system.serviceModel>
    <diagnostics>
        <messageLogging logEntireMessage="true" logMalformedMessages="true"
         logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" />
    </diagnostics>
    <behaviors>
        <serviceBehaviors>
            <behavior name="includeExceptions">
                <serviceDebug includeExceptionDetailInFaults="true"/>
                <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <bindings>
        <netTcpBinding>
            <binding name="NetTcpBinding_Default" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="Infinite" sendTimeout="01:00:00" portSharingEnabled="true" transferMode="Buffered" maxReceivedMessageSize="2147483647">
                <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
                <security mode="Transport">
                    <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign"/>
                </security>
            </binding>
        </netTcpBinding>
    </bindings>

</system.serviceModel>
4

2 回答 2

7

手动创建代理不会妨碍您将配置放入配置文件;您只需要在 ClientBase 派生的代理类中公开正确的构造函数重载,该代理类委托给 ClientBase 中的正确构造函数,该构造函数采用端点名称在配置中查找。

也就是说,您当然可以通过代码填写端点标识,您只需创建正确类型的 EndpointIdentity 派生类并将其附加到您在实例化代理类时使用的 EndpointAddress 对象。像这样的东西:

EndpointIdentity epid = EndpointIdentity.CreateUpnIdentity("user@domain.fqdn");
EndpointAddress epaddr = new EndpointAddress(uri, epid);

MyClient client = new MyClient(epaddr);
于 2009-08-06T12:46:05.760 回答
1

尽管我可能不会直接回答您的问题,但要在栅栏的两侧使用相同的数据成员,您无需手动创建代理。您所做的是使用 svcutil 生成代理,然后传入将数据成员作为 /r 的 dll

例如

svcutil http://localhost/service/service.svc /r:AssemblyThatHasDataMembers.dll /out:ServiceProxy.cs

这样,数据成员类型就不会在您的 ServiceProxy.cs 文件中重复。您可以通过传递 wsdl/xsd(真正的契约优先方法)来广泛地自定义它,使用 /ct 自定义集合类型等。

这将为您节省大量手动制作代理的时间,同时避免您可能遇到的上述问题,因为一切都会成为库存标准。

于 2009-08-05T23:20:28.643 回答