.net core 2.2.0 SOAP踩坑

Posted coolyuwk

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了.net core 2.2.0 SOAP踩坑相关的知识,希望对你有一定的参考价值。

首先确认下面几个程序集是最新版本:

<PackageReference Include="System.ServiceModel.Http" Version="4.5.3" />
<PackageReference Include="System.ServiceModel.NetTcp" Version="4.5.3" />
<PackageReference Include="System.ServiceModel.Primitives" Version="4.5.3" />
<PackageReference Include="System.ServiceModel.Security" Version="4.5.3" />

 

org.xml.sax.SAXException: SimpleDeserializer encountered a child element

大概率是出在sendbody格式上,通过SoapUI测试可以看到正确的数据格式。

 

如果是HTTPS需要在客户端加上如下代码:

client.ClientCredentials.ServiceCertificate.SslCertificateAuthentication = new System.ServiceModel.Security.X509ServiceCertificateAuthentication()
                
                    CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.Custom,
                    RevocationMode = X509RevocationMode.NoCheck,
                    CustomCertificateValidator = new MyX509CertificateValidator("anything")
                ;


    public class MyX509CertificateValidator : X509CertificateValidator
    
        string allowedIssuerName;

        public MyX509CertificateValidator(string allowedIssuerName)
        
            this.allowedIssuerName = allowedIssuerName;
        

        public override void Validate(X509Certificate2 certificate)
        
            Console.WriteLine($"X509证书:certificate?.IssuerName?.Name");
        
    

  

以上是关于.net core 2.2.0 SOAP踩坑的主要内容,如果未能解决你的问题,请参考以下文章

尝试使用 net core / net 5 连接 SOAP 服务

Ubuntu ARM64下的.NET Core 踩坑记录

Mac上踩坑.net core开发

.net Core 踩坑记:全新零框架项目搭建

asp net core soap请求ws-addressing

在 SOAP 请求 .NET CORE 2.2 上发送的 Http.WinHttpException。收到的消息是意外的或格式错误