I added code to make the binding use the certificate (highlighted line 9 below) and then specified the certificate to use in the client proxy object. My certificate is installed into the Personal store on the local machine (highlighted line 13 below).
Upon testing the code (sans line 10). I received an error "If this is a legitimate remote endpoint, you can fix the problem by explicitly specifying DNS identity '
$proxy = "http://ws.logos.domain:8181/LogosService.svc"; & 'C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\SvcUtil.exe' "$proxy?wsdl" & 'C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe' /t:library LogosService.cs /r:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\System.ServiceModel.dll" [Reflection.Assembly]::LoadWithPartialName("System.ServiceModel"); [Reflection.Assembly]::LoadFrom("$pwd\LogosService.dll"); $wsHttpBinding = New-Object System.ServiceModel.WSHttpBinding; $wsHttpBinding.Security.Message.ClientCredentialType = [System.ServiceModel.MessageCredentialType]::Certificate; $endpoint = New-Object System.ServiceModel.EndpointAddress($memberProxy, [System.ServiceModel.EndpointIdentity]::CreateDNSIdentity("ws.Logos")) $proxy = New-Object MemberServiceClient($wsHttpBinding, $endpoint) $proxy.ClientCredentials.ClientCertificate.SetCertificate([System.Security.Cryptography.X509Certificates.StoreLocation]::LocalMachine, [System.Security.Cryptography.X509Certificates.StoreName]::My, [System.Security.Cryptography.X509Certificates.X509FindType]::FindBySubjectName, "ws.Logos"); $request = New-Object LogosService.ServiceContracts.GetUserInfoRequest; $request.RequestId = [Guid]::NewGuid(); $request.login = 'domain\test'; $response = $proxy.GetUserInfo($request);
Once I had the $response object, I could get at all the information I needed. Pretty useful.
No comments:
Post a Comment