.NET CORE 3.1中的WSDL导入



我是.net core 3.1 的新手

我有以下问题,当我引用WSDL并创建引用时,当我试图启动Web服务时,它会向我请求一个";端点配置";在构造函数中,我不知道它是什么,也不知道如何创建它。

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

示例构造函数

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;
}
}

更新errorClientWs

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

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

更多详细信息,你可以查看这个线程:

如何使用.NET Core 3.0 WPF应用中的SOAP web服务

最新更新