C# USCG PSIX Web服务返回身份验证错误
美国海岸警卫队运行一个名为PSIX的SOAP Web服务:C# USCG PSIX Web服务返回身份验证错误,c#,wcf,.net-core,soap,C#,Wcf,.net Core,Soap,美国海岸警卫队运行一个名为PSIX的SOAP Web服务: 最近,一些已经访问此web服务一段时间的软件开始出错,PSIX返回的错误为: 客户端身份验证方案“匿名”禁止HTTP请求。 网站上的证书有问题,但只要我们访问该服务(一年半多一点),就一直是这样 在USCG网站上,我找不到任何关于访问该服务需要任何身份验证的信息,因此我不确定该怎么办。我也找不到该服务的详细联系方式,可以询问他们是否改变了自己的想法——有一个评论表,我已经向它提交了关于这个问题的问题 该服务是使用Microso
客户端身份验证方案“匿名”禁止HTTP请求。
网站上的证书有问题,但只要我们访问该服务(一年半多一点),就一直是这样
在USCG网站上,我找不到任何关于访问该服务需要任何身份验证的信息,因此我不确定该怎么办。我也找不到该服务的详细联系方式,可以询问他们是否改变了自己的想法——有一个评论表,我已经向它提交了关于这个问题的问题
该服务是使用Microsoft WCF Web服务参考提供程序添加到.NET核心项目中的。我们创建一个实例,如果它使用这个静态助手方法
关于如何避免这个错误有什么想法吗
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;
}
}
}
下面的代码非常有用。如果您的机器出现故障,则可能是TLS问题:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication1
{
class Program
{
const string URL = "https://cgmix.uscg.mil/xml/PSIXData.asmx?WSDL";
static void Main(string[] args)
{
XDocument doc = XDocument.Load(URL);
}
}
}
我猜USCG在某种程度上改变了他们web服务的URL。因此,我:
- 已删除并重新添加WCF连接的服务引用
- 将我的服务代理助手方法更改为使用新的URL(我认为这是我的问题的根本原因)
- 我需要绕过证书错误
- 我需要增加默认的消息/缓冲区大小,因为其中一些调用可以返回大量信息
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"));
var factory = new ChannelFactory<PSIXDataSoap>(binding, new EndpointAddress("https://cgmix.uscg.mil/xml/PSIXData.asmx")); //<--- NEW URL
//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;
}
}
}
私有静态PSIXDataSoap服务代理
{
得到{
尝试
{
如果(_serviceProxy==null)
{
BasicHttpBinding=null;
binding=newBasicHttpBinding(BasicHttpSecurityMode.Transport);//强制使用SSL,否则会得到“预期的http”
binding.MaxReceivedMessageSize=20000000;
binding.MaxBufferSize=20000000;
binding.MaxBufferPoolSize=20000000;
binding.AllowCookies=true;
//var factory=newchannelfactory(绑定,新端点地址(“https://psix.uscg.mil/xml/PSIXData.asmx"));
var factory=newchannelfactory(绑定,新端点地址(“https://cgmix.uscg.mil/xml/PSIXData.asmx);//我也可以检索WSDL,但尝试运行任何操作(如getVesselSummaryAsync
都会导致错误。在获得结果时为什么需要访问代理。只需解析xml结果即可。
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"));
var factory = new ChannelFactory<PSIXDataSoap>(binding, new EndpointAddress("https://cgmix.uscg.mil/xml/PSIXData.asmx")); //<--- NEW URL
//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;
}
}
}