gpt4 book ai didi

.net - 使用 WCF 模拟和 net.tcp 绑定(bind)访问 web.config 设置

转载 作者:行者123 更新时间:2023-12-04 14:43:16 24 4
gpt4 key购买 nike

我正在尝试对 IIS 7 中托管的 WCF 服务(使用 net.tcp 绑定(bind))使用模拟。我已经到了模拟客户端的地步,但每当我尝试访问 Web 中的任何配置设置时.config 使用 Settings.Default.SomeSetting 它会抛出 SettingsPropertyNotFoundException。这是因为 IIS 以与模拟身份不同的身份运行吗?如果是这样,我必须更改哪些设置以允许它们在相同的模拟身份下运行?我试过设置“servicePrincipalName”属性,但没有成功。

我在下面包含了我的 web.config 设置:

<system.serviceModel>
<services>
<service name="TestServices">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="tcpbinding"
contract="Test.ITestService">
<identity>
<servicePrincipalName value="NT AUTHORITY\NETWORK SERVICE" />
</identity>
</endpoint>
<endpoint address="mextcp" binding="mexTcpBinding" contract="IMetadataExchange" />
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<bindings>
<netTcpBinding>
<binding name="tcpbinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" portSharingEnabled="true">
<security mode="Transport">
<transport clientCredentialType="Windows" protectionLevel="None"/>
<message clientCredentialType="Windows"/>
</security>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- 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="true" />
<serviceAuthorization impersonateCallerForAllOperations="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>

最佳答案

我似乎没有在服务器端正确模拟我的客户端,因为我需要将客户端上的 allowedImpersonationLevel 设置为“模拟”。这默认为“标识”。因此,当我使用 WindowsIdentity.GetCurrent().Name 进行测试时,我得到了正确的用户名,但实际上并未模拟该用户。

所以将它添加到我的客户端 web.config 中就可以了:

    <client>
<endpoint address="net.tcp://localhost/Test/Service/TestService.svc"
binding="netTcpBinding" bindingConfiguration="NetTcpBinding_ITestService"
contract="ServiceReference.ITestService" name="NetTcpBinding_ITestService"
behaviorConfiguration="ImpersonationBehavior">
</endpoint>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="ImpersonationBehavior">
<clientCredentials>
<windows allowedImpersonationLevel="Impersonation" />
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>

关于.net - 使用 WCF 模拟和 net.tcp 绑定(bind)访问 web.config 设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2039250/

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