在.NET CORE 3.1中导入WSDL

问题描述

我是.net core 3.1的新手

我遇到以下问题,当我引用WSDL并创建引用时,当我尝试启动Web服务时,它要求我在构造函数中输入“ Endpointconfiguration”,但我不知道它是什么或如何创建它。

WSMP.Service1SoapClient WS = new WSMP.Service1SoapClient();

example constructor

ty

更新

我为服务使用了此构造函数,但是我在图像中附加了错误,在.net中它可以正常工作,但是在.net core中,它不起作用,我不知道我是否有错误新Service1SoapClient的配置(basicHttpBinding,endpointAddress));

 public class SoapMultiPay : ISoapDemoApiMp
{
    public readonly string serviceUrl = "http://xxx.xxx.xx.x:xxx/Service1.asmx";
    public readonly EndpointAddress endpointAddress;
    public readonly BasicHttpBinding basicHttpBinding;

    public SoapMultiPay()
    {
        endpointAddress = new EndpointAddress(serviceUrl);
        basicHttpBinding = new BasicHttpBinding();
        basicHttpBinding.MaxBufferSize = int.MaxValue;
        basicHttpBinding.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
        basicHttpBinding.MaxReceivedMessageSize = int.MaxValue;
        basicHttpBinding.AllowCookies = true;
    }
    public async Task<Service1SoapClient> GetInstanceAsync()
    {
        return await Task.Run(() => new Service1SoapClient(basicHttpBinding,endpointAddress));
    }
    public async Task<RespuestaCotizadorGiro> GetCotizadorGiro(string zipCode)
    {
        var client = await GetInstanceAsync();
        var response = await client.CotizadorGiroAsync(null,null);
        return response;
    }
}

Update-errorClientWs

解决方法

您的WSDL似乎包含多个端点,在这种情况下,当您创建服务客户端实例时,您必须分配端点,尝试使用如下代码:

ServiceReference2.Service1Client client1 = new ServiceReference2.Service1Client(ServiceReference2.Service1Client.EndpointConfiguration.BasicHttpBinding_IService1); 
var response2 = client1.GetDataAsync(34); 
MyLabel.Content += " " + response2.Result;

更多详细信息,您可以检查此线程:

How to consume SOAP web service from .NET Core 3.0 WPF app