gpt4 book ai didi

WCF - 更改端点地址会导致安全异常

转载 作者:行者123 更新时间:2023-12-04 14:34:52 25 4
gpt4 key购买 nike

当客户端使用以下默认选项生成服务时,我的 WCF 服务使用 wsHttpBinding 并在客户端正常工作:

RServiceClient R = new RServiceClient();

但是,在某些时候,我需要能够指定服务的位置,大概是通过如下更改端点地址:
RServiceClient R = new RServiceClient();
R.Endpoint.Address = new EndpointAddress(new Uri "http://xxx.xxxx.xxx:80/RServer/RService.svc"));

但是,当我指定确切的端点时,我得到一个 SecurityNegotiationException:
System.ServiceModel.Security.SecurityNegotiationException 未处理
Message="调用者未通过服务的身份验证。"
来源="mscorlib"....

WCF 服务在 IIS 上运行,并在 IIS 管理员下启用了匿名访问。此外,当客户端与管理员帐户下的服务在同一台机器上运行时,会发生此错误 - 我还没有到通过网络运行它的可怕部分!

有任何想法吗?

最佳答案

默认情况下,wsHttpBinding 使用 Windows 身份验证。我不确定 IIS 中的托管如何影响这种情况。

如果你不想开启安全,你可以添加一个安全元素,并在两端的配置中将模式元素设置为“无”以关闭默认设置。

我认为这可能会奏效——我添加了 wsHttpBinding 部分并将服务的 bindingConfiguration 设置为指向新添加的绑定(bind)属性:

<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="wsHttpBind">
<security mode="None">
<transport clientCredentialType="None" protectionLevel="EncryptAndSign" />
<message clientCredentialType="None" algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="ServiceBehavior"
name="RService">
<endpoint address=""
binding="wsHttpBinding"
bindingConfiguration="wsHttpBind"
name="RService"
contract="IRService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex"
binding="mexHttpBinding"
name="MetadataExchange"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<!-- 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"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>

关于WCF - 更改端点地址会导致安全异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/246636/

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