下面是我为向我们拥有的内部 Web 服务发出 SOAP 请求而编写的代码片段。如果我使用 Fiddler 运行此程序,运行 Fiddler 会提醒该站点正在请求证书。如果我向 Fiddler 提供证书,它会完美运行。如果我关闭 Fiddler,则会收到连接已关闭的错误消息。我正在撞墙,因为我将证书添加到 ClientCertificates 集合中,当我调试它时,我可以看到它有它。任何想法为什么它不在运行时呈现它?(你会看到我在哪里测试过从本地机器存储中获取它并从文件中创建它,并且这两个选项都不起作用)
$cert = [System.Security.Cryptography.X509Certificates.X509Certificate2]::CreateFromCertFile($certPath)
#$cert = get-item cert:\LocalMachine\* | get-ChildItem | Where-Object -FilterScript {($_.FriendlyName -eq "HRSYS")}
$soapWebRequest = [System.Net.WebRequest]::Create($url)
$soapWebRequest.ClientCertificates.Add($cert)
$soapWebRequest.Headers.Add("SOAPAction", "http://service.wellsfargo.com/provider/hr/entity/teamMemberData/getTeamMemberProfileById/2010/12/")
$soapWebRequest.ContentType = "text/xml;charset=`"utf-8`""
$soapWebRequest.Accept = "text/xml"
$soapWebRequest.Method = "POST"
$soapWebRequest.Timeout = 60000
$soapWebRequest.UseDefaultCredentials = $true