且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

WCF 客户端:第一次调用失败,第二次调用成功

更新时间:2023-02-25 20:35:49

出于某种原因,这仅发生在一台测试服务器上,而不发生在其他服务器上.对外部 SOAP 网络服务调用的跟踪日志显示内部函数 AcquireCredentialsHandle 失败,错误代码为 0X8009030D.

For some reason this only occurred on one test server, and not other servers. A trace log of the call to the external SOAP webservice showed that the internal function AcquireCredentialsHandle failed with error code 0X8009030D.

经过更多调查后,我发现了一些安装在相关服务器上的证书(来自外部 SOAP 网络服务).它们似乎与对外部 SOAP 网络服务的调用相冲突.删除这些证书后,第一次调用成功!

After some more investigation I found several certificates (from the external SOAP webservice) that were installed on the server in question. They seemed to be conflicting with the call to the external SOAP webservice. After deleting these certificates, the first call now succeeds!

更新:我再次遇到同样的问题,但现在在我的开发机器上.清除证书无济于事,所有请求都以相同的SecurityNegotiationException失败.为了解决这个问题,我为 HTTP 100 状态代码添加了一个传递,并强制连接到 TLS 1.2:

Update: I encountered the same problem again, but now on my development machine. Cleaning certificates did not help, and all requests failed with the same SecurityNegotiationException. To fix this, I've added a pass-through for HTTP 100 status codes, and forced the connection to TLS 1.2:

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

请注意,我在之前添加了此代码,我在初始化 WCF 客户端(问题帖子中的MyEndpointClient)以确保 WCF 客户端使用这些设置.

Note that I added this code before I initialised the WCF Client (MyEndpointClient in the question's post), to make sure the WCF Client uses these settings.