gpt4 book ai didi

database - WCF 服务不模拟客户端

转载 作者:搜寻专家 更新时间:2023-10-30 20:45:14 25 4
gpt4 key购买 nike

物流:1 台运行 WCF 服务的服务器。1 台服务器为 WCF 服务运行数据库。

问题:我有一个运行在 1 台服务器上的 WCF 服务,它连接到一个单独的服务器以获取它需要检索的必要数据。我的问题是,当从客户端计算机调用服务时,我收到一条数据库 SQL 错误,指出“用户‘NT AUTHORITY\ANONYMOUS LOGON’登录失败”。我相信我已经设置了 WCF 服务来使用模拟。

WCF 服务器配置:

<bindings>
<ws2007HttpBinding>
<binding maxReceivedMessageSize="214748">
<security mode="Message">
<transport clientCredentialType="Windows"
proxyCredentialType="Windows" realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</ws2007HttpBinding>
</bindings>
<services>
<service behaviorConfiguration="Host.ServiceBehavior" name="Wcf.MyWebService">
<endpoint address="" behaviorConfiguration=""
binding="ws2007HttpBinding" contract="Wcf.MyWebServiceSoap">
<identity>
<servicePrincipalName value="ServerMachineName" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Host.ServiceBehavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceAuthorization impersonateCallerForAllOperations="true" />
</behavior>
</serviceBehaviors>
</behaviors>

WCF 服务代码:

public class MySebService: MyWebServiceSoap
{
[OperationBehavior(Impersonation = ImpersonationOption.Required)]
public string TestWebMethod()
{
DbDal dal = CreateDataAccessLayer();

return dal.GetStringFromDatabase();
}
}

客户端配置和代码:

我正在以编程方式设置以下配置项:

public void TestWebMethod()
{
WS2007HttpBinding binding = new WS2007HttpBinding();
EndpointAddress endpoint = new EndpointAddress("uri");
ServiceClient client = new ServiceClient(binding, endpoint);
client.ClientCredentials.Windows.AllowedImpersonationLevel =
TokenImpersonationLevel.Impersonation;
client.ClientCredentials.Windows.AllowNtlm = true;
string result = client.TestWebMethod();
client.Close();
}

最佳答案

TokenImpersonationLevel.Impersonation 允许服务访问服务本地的资源,但不允许服务访问外部资源(例如,另一个服务)。

您必须将允许的模拟级别设置为 TokenImpersonationLevel.Delegation

client.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Delegation;

关于database - WCF 服务不模拟客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4372606/

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