如何设置ClientCredentials? [英] How can I set ClientCredentials?

查看:237
本文介绍了如何设置ClientCredentials?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图消耗WCF服务:



该服务的配置是:



<预类=郎咸平的XML prettyprint-覆盖> <?XML版本=1.0编码=UTF-8>?;
<结构>
< system.serviceModel>
<&绑定GT;
< netNamedPipeBinding>
<绑定名称=netNamedPipeEndpointcloseTimeout =0点01分00秒
openTimeout =0点01分00秒receiveTimeout =0点10分○○秒的SendTimeout =0时01分: 00
transactionFlow =假transferMode =缓冲transactionProtocol =OleTransactions
hostNameComparisonMode =StrongWildcardmaxBufferPoolSize =524288
MAXBUFFERSIZE =65536MAXCONNECTIONS =10maxReceivedMessageSize =65536>
< readerQuotas MAXDEPTH =32maxStringContentLength =8192maxArrayLength =16384
maxBytesPerRead =4096maxNameTableCharCount =16384/>
<安全模式=无>
<运输的ProtectionLevel =EncryptAndSign/>
< /安全>
< /&结合GT;
< / netNamedPipeBinding>
<&NetTcpBinding的GT;
<绑定名称=netTcpEndpointcloseTimeout =00:01:00openTimeout =00:01:00
receiveTimeout =00:10:00的SendTimeout =00:01: 00transactionFlow =假
transferMode =缓冲transactionProtocol =OleTransactions
hostNameComparisonMode =StrongWildcard将ListenBackLog =10
maxBufferPoolSize =524288MAXBUFFERSIZE =65536MAXCONNECTIONS =10
maxReceivedMessageSize =65536>
< readerQuotas MAXDEPTH =32maxStringContentLength =8192maxArrayLength =16384
maxBytesPerRead =4096maxNameTableCharCount =16384/>
<有序的ReliableSession =真正的inactivityTimeout =00:10:00$ B $ =使假/> B:
<安全模式=无>
<运输clientCredentialType =窗口的ProtectionLevel =EncryptAndSign/>
<消息clientCredentialType =的Windows/>
< /安全>
< /&结合GT;
< / NetTcpBinding的>
<&的wsHttpBinding GT;
<绑定名称=wsHttpBindingConfigurationcloseTimeout =00:01:00
openTimeout =00:01:00receiveTimeout =00:10:00的SendTimeout =00:01: 00
bypassProxyOnLocal =假transactionFlow =假hostNameComparisonMode =StrongWildcard
maxBufferPoolSize =524288maxReceivedMessageSize =6​​5536
messageEncoding =文本textEncoding =utf-8的useDefaultWebProxy =真正的
allowCookies =false的>
< readerQuotas MAXDEPTH =32maxStringContentLength =8192maxArrayLength =16384
maxBytesPerRead =4096maxNameTableCharCount =16384/>
<有序的ReliableSession =真正的inactivityTimeout =00:10:00$ B $ =使假/> B:
<安全模式=无>
<运输clientCredentialType =视窗proxyCredentialType =无
境界=/>
<消息clientCredentialType =视窗negotiateServiceCredential =真/>
< /安全>
< /&结合GT;
< /&的wsHttpBinding GT;
< /绑定>
<客户端>
<端点地址=的net.tcp://webapppro-v11/FlightInfoWebService/FlightInfoService.svc
结合=NetTcpBinding的bindingConfiguration =netTcpEndpoint
合同=FlightInfoService的名字=netTcpEndpoint/>
<端点地址=net.pipe://webapppro-v11/FlightInfoWebService/FlightInfoService.svc
结合=netNamedPipeBindingbindingConfiguration =netNamedPipeEndpoint
合同=FlightInfoService的名字=netNamedPipeEndpoint/>
<端点地址=HTTP://webapppro-v11/FlightInfoWebService/FlightInfoService.svc
结合=的wsHttpBindingbindingConfiguration =wsHttpBindingConfiguration
合同=FlightInfoServiceNAME = wsHttpBindingConfiguration/>
< /客户>
< /system.serviceModel>
< /结构>

当我尝试调用该服务:

 公共异步无效LoadCities()
{
_client =新FlightInfoServiceClient(Maquette_MyAirport_Win8.FlightService.FlightInfoServiceClient.EndpointConfiguration.wsHttpBindingConfiguration,http://servuucs.fr/ FlightInfoWebService / FlightInfoService.svc);

VAR citiesResponse =等待_client.GetAllCitiesAsync(新BaseRequest());
VAR myCities = citiesResponse.Cities;
}



我捕获这个异常:




错误:UnAuthorizedAccess说明:您无权访问此服务




我又能怎么样设置我的ClientCredentials?


解决方案

作为@Paciv在评论中指出的那样,你可以通过代码做到这一点。与物业 ClientCredentials.Windows 的,这样的事情他们设置

  _client.ClientCredentials.Windows.ClientCredential.Domain =warzone42; 
_client.ClientCredentials.Windows.ClientCredential.UserName =user1428798;
_client.ClientCredentials.Windows.ClientCredential.Password =P @ ssw0rd

在代码中设置凭据当然是不明智的。如果不设置的Windows用户编程如上,我相信从用户运行该客户端的凭据发送翻过(这也许是一个比较典型的情况呢?)。



请注意,如果你设置的代码证书,你可能实际上会寻找的UserName认证


I'm trying to consume a WCF service:

The config of the service is:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <netNamedPipeBinding>
                <binding name="netNamedPipeEndpoint" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
                    hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288"
                    maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport protectionLevel="EncryptAndSign" />
                    </security>
                </binding>
            </netNamedPipeBinding>
            <netTcpBinding>
                <binding name="netTcpEndpoint" closeTimeout="00:01:00" openTimeout="00:01:00"
                    receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false"
                    transferMode="Buffered" transactionProtocol="OleTransactions"
                    hostNameComparisonMode="StrongWildcard" listenBacklog="10"
                    maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
                    maxReceivedMessageSize="65536">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="None">
                        <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                        <message clientCredentialType="Windows" />
                    </security>
                </binding>
            </netTcpBinding>
            <wsHttpBinding>
                <binding name="wsHttpBindingConfiguration" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                    allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="None">
                        <transport clientCredentialType="Windows" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="Windows" negotiateServiceCredential="true" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="net.tcp://webapppro-v11/FlightInfoWebService/FlightInfoService.svc"
                binding="netTcpBinding" bindingConfiguration="netTcpEndpoint"
                contract="FlightInfoService" name="netTcpEndpoint" />
            <endpoint address="net.pipe://webapppro-v11/FlightInfoWebService/FlightInfoService.svc"
                binding="netNamedPipeBinding" bindingConfiguration="netNamedPipeEndpoint"
                contract="FlightInfoService" name="netNamedPipeEndpoint" />
            <endpoint address="http://webapppro-v11/FlightInfoWebService/FlightInfoService.svc"
                binding="wsHttpBinding" bindingConfiguration="wsHttpBindingConfiguration"
                contract="FlightInfoService" name="wsHttpBindingConfiguration" />
        </client>
    </system.serviceModel>
</configuration>

When I try to call the service:

public async void LoadCities()
{
    _client = new FlightInfoServiceClient(Maquette_MyAirport_Win8.FlightService.FlightInfoServiceClient.EndpointConfiguration.wsHttpBindingConfiguration, "http://servuucs.fr/FlightInfoWebService/FlightInfoService.svc");

    var citiesResponse = await _client.GetAllCitiesAsync(new BaseRequest());
    var  myCities = citiesResponse.Cities;
}

I catch this exception:

ERROR: UnAuthorizedAccess description:You are not authorized to access this service

How can I set my ClientCredentials?

解决方案

As @Paciv noted in a comment, you can do this through code. Set them with the property ClientCredentials.Windows, something like this:

_client.ClientCredentials.Windows.ClientCredential.Domain = "warzone42";
_client.ClientCredentials.Windows.ClientCredential.UserName = "user1428798";
_client.ClientCredentials.Windows.ClientCredential.Password = "p@ssw0rd";

Setting the credentials in code is of course unwise. If you don't set the Windows user programmatically as above, I believe the credentials from the user running the client are sent accross (which is perhaps a more typical situation?).

Note that if you're setting credentials in code you may in fact be looking for UserName authentication.

这篇关于如何设置ClientCredentials?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆