【问题标题】:WSDL import in .NET CORE 3.1.NET CORE 3.1 中的 WSDL 导入
【发布时间】:2021-01-01 12:11:11
【问题描述】:

我是 .net core 3.1 的新手

我有以下问题,当我引用 WSDL 并创建引用时,当我尝试启动 web 服务时,它会在构造函数中询问我“端点配置”,我不知道它是什么或如何创建它。

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

example constructor

ty

更新

我将此构造函数用于服务,但我在图像中附加了错误,在 .net 中它可以正常工作,但在 .net 核心中它不起作用,我不知道我是否有问题新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

【问题讨论】:

  • 根据您的描述,我尝试创建一个Web服务,并use the WCF Web Service Reference Provider Tool添加Web服务引用,然后,我可以使用服务客户端成功,您可以检查the screenshot。尝试使用上述步骤重新检查您的Web服务,如果仍然无法正常工作,可能服务客户端实例需要参数,请检查构造函数并添加参数。
  • 你好更新问题非常感谢@ZhiLv
  • 您的 WSDL 似乎包含多个端点,在这种情况下,当您创建服务客户端实例时,您必须分配端点,尝试使用这样的代码:ServiceReference2.Service1Client client1 = new ServiceReference2.Service1Client(ServiceReference2.Service1Client.EndpointConfiguration.BasicHttpBinding_IService1); var response2 = client1.GetDataAsync(34); MyLabel.Content += " " + response2.Result;。参考:stackoverflow.com/questions/57445647/…
  • 是的,这工作!!!!!!
  • 谢谢sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss!!

标签: .net asp.net-core .net-core asp.net-core-mvc wsdl


【解决方案1】:

您的 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-10
    • 2020-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-15
    • 1970-01-01
    • 2021-01-24
    相关资源
    最近更新 更多