我正在开发一个 Powershell 脚本,它需要调用一个 Web 服务,并带有一个客户端和服务证书。我在 C# .Net 中有连接半工作。在 .Net app.config 我有这些配置:
...
<security mode="TransportWithMessageCredential">
<message clientCredentialType="Certificate" negotiateServiceCredential="false" establishSecurityContext="false"/>
<transport clientCredentialType="Certificate"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="CertificateAuthenticationBehavior">
<clientCredentials>
<clientCertificate findValue="Capital Market FIONAsi" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" />
<serviceCertificate>
<defaultCertificate findValue="example.dk" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName"/>
<authentication certificateValidationMode="PeerTrust" />
</serviceCertificate>
</clientCredentials>
</behavior>
.net 代码。
var stinaProxy = new StinaServiceProxy("StinaService");
var stinaHandshakeResponse = stinaProxy.HandShake(testValueArgument);
这似乎让我通过了 .net 中的证书验证
但如前所述,我实际上需要这个在 powershell 中为我工作。我不知道如何调用 Web 服务并提供客户端和服务证书。
这是我到目前为止在 powershell 中得到的,但它以超时结束,我相信这是一个证书问题。
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$ClientCertificate = Get-ChildItem Cert:\LocalMachine\My\af4269b1d7190be23f1e48001fc345011f7ade80
$defaultCertificate = Get-ChildItem Cert:\LocalMachine\My\42097f29a5bd2fb4d9960e74f67654d369b7a2e3
$url = "https://example.dk/StinaService.svc?wsdl"
$webserviceex = New-WebServiceProxy -Uri $url -Namespace WebServiceProxy
$webserviceex.Timeout = 5000
$webserviceex.ClientCertificates.Add($ClientCertificate)
$webserviceex.ClientCertificates.Add($defaultCertificate)
$handshakeResult = $webserviceex.HandShake("1234!")
任何帮助表示赞赏:)