【发布时间】:2021-07-01 17:34:42
【问题描述】:
美国海岸警卫队运行一个名为 PSIX 的 SOAP Web 服务:
- https://cgmix.uscg.mil/xml/default.aspx
- https://cgmix.uscg.mil/xml/PSIXData.asmx
- https://cgmix.uscg.mil/xml/PSIXData.asmx?WSDL
最近一段时间访问该Web服务的一些软件开始报错,从PSIX返回的错误是:
The HTTP request was forbidden with client authentication scheme 'Anonymous'.
网站上的证书有问题,但只要我们访问该服务(一年半多一点)就一直是这样。
我在 USCG 网站上没有提到您需要任何类型的身份验证才能访问该服务 - 所以我不确定该怎么做。也没有提供服务的联系方式,我可以找到询问他们是否改变了他们方面的一些东西 - 我已经提交了一个关于这个问题的问题的评论表。
使用 Microsoft WCF Web Service Reference Provider 将服务添加到 .NET Core 项目中。如果它使用这个静态辅助方法,我们会创建一个实例。
关于如何绕过错误的任何想法?
private static PSIXDataSoap ServiceProxy
{
get {
try
{
if (_serviceProxy == null)
{
BasicHttpBinding binding = null;
binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport); //Force use SSL, otherwise you get "expected http"
binding.MaxReceivedMessageSize = 20000000;
binding.MaxBufferSize = 20000000;
binding.MaxBufferPoolSize = 20000000;
binding.AllowCookies = true;
var factory = new ChannelFactory<PSIXDataSoap>(binding, new EndpointAddress("https://psix.uscg.mil/xml/PSIXData.asmx"));
//Tell it: Yes, I know the Coast Guard's Certificate is invalid...
factory.Credentials.ServiceCertificate.SslCertificateAuthentication =
new X509ServiceCertificateAuthentication()
{
CertificateValidationMode = X509CertificateValidationMode.None,
RevocationMode = X509RevocationMode.NoCheck
};
_serviceProxy = factory.CreateChannel();
}
return _serviceProxy;
}
catch (Exception)
{
return null;
}
}
}
然后像这样访问代理:
var psixResponse = await ServiceProxy.getVesselSummaryAsync(vesselId_str, vesselName_str, callsign_str, vin_str, hin_str, flag_str, service_str, buildYear_str);
【问题讨论】: