.NET CORE 3.1 中的 WSDL 导入

WSDL import in .NET CORE 3.1

我是 .net core 3.1 的新手

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

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

example constructor

更新

我为服务使用了这个构造函数,但是我在图像中看到了错误,在 .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