Гость
Форумы / WCF, Web Services, Remoting [игнор отключен] [закрыт для гостей] / Перевод конфига в код / 2 сообщений из 2, страница 1 из 1
02.08.2010, 13:13
    #36770876
barrabas
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Перевод конфига в код
есть работающий конфиг
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
<system.serviceModel>
		<behaviors>
			<endpointBehaviors>
				<behavior name="CertificateBehavior" >
					<clientCredentials>
						<clientCertificate findValue="ProkofievVS_Client" storeLocation="CurrentUser" storeName="My" x509FindType="FindBySubjectName"/>
						--><!--<clientCertificate findValue="WcfClient" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName"/>--><!--
						<serviceCertificate>
							<authentication certificateValidationMode="PeerTrust" trustedStoreLocation="CurrentUser"/>
						</serviceCertificate>
					</clientCredentials>
				</behavior>
			</endpointBehaviors>
		</behaviors>

		<bindings>
			<netTcpBinding>
				<binding name="NetTcpBinding_IGsService" 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="true"/>
					<security mode="TransportWithMessageCredential">
						<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign"/>
						<message clientCredentialType="Certificate" algorithmSuite="Default"/>
					</security>
				</binding>
	
			</netTcpBinding>
		</bindings>
		
		<client>
			<endpoint address="net.tcp://castle/Barrabas.WcfService.Head/WcfServiceGs.svc" 
					  binding="netTcpBinding" 
					  bindingConfiguration="NetTcpBinding_IGsService" 
					  contract="IGsService" 
					  name="NetTcpBinding_IGsService"
					  behaviorConfiguration="CertificateBehavior" >
				
				<identity>
					<dns value="WMSvc-CASTLE"/>
				</identity>
			</endpoint>
		</client>
		
	</system.serviceModel>


хочу реализовать тоже самое но в коде
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
            Binding binding = new NetTcpBinding(SecurityMode.TransportWithMessageCredential, true);
            EndpointAddress endPoint = new EndpointAddress(
                new Uri("net.tcp://castle/Barrabas.WcfService.Head/WcfServiceGs.svc"),
                EndpointIdentity.CreateDnsIdentity("WMSvc-CASTLE"));
            
            _client = new GsServiceClient(binding, endPoint);
             
            _client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode =
                System.ServiceModel.Security.X509CertificateValidationMode.PeerTrust;

            _client.ClientCredentials.ClientCertificate.SetCertificate(
                System.Security.Cryptography.X509Certificates.StoreLocation.CurrentUser,
                System.Security.Cryptography.X509Certificates.StoreName.My,
                System.Security.Cryptography.X509Certificates.X509FindType.FindBySubjectName,
                "ProkofievVS_Client");

            string test = _client.Test();

ловлю ошибку

Код: plaintext
1.
2.
3.
Secure channel cannot be opened because security negotiation with the remote endpoint has failed. 
This may be due to absent or incorrectly specified EndpointIdentity in the EndpointAddress used to
create the channel. Please verify the EndpointIdentity specified or implied by the EndpointAddress
correctly identifies the remote endpoint.
...
Рейтинг: 0 / 0
02.08.2010, 13:35
    #36770913
barrabas
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Перевод конфига в код
Нужно было заменить первую строчку кода на

Код: plaintext
1.
2.
            NetTcpBinding binding = new NetTcpBinding(SecurityMode.TransportWithMessageCredential, true);
            binding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate;
...
Рейтинг: 0 / 0
Форумы / WCF, Web Services, Remoting [игнор отключен] [закрыт для гостей] / Перевод конфига в код / 2 сообщений из 2, страница 1 из 1
Целевая тема:
Создать новую тему:
Автор:
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]