How add WSDL web reference to.NET Standard library

Viewed 5828

I need to consume this WSDL: https://testapi2.schenker.pl/services/TransportOrders?wsdl

But I have a problem with adding reference to .NET Standard library.

For .NET Framework library I had options to add web reference like on below screens.

But for .NET Standard or .NET Framework I have completely different options for that.

Also I get warnings:

Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.
XPath to wsdl:binding: //wsdl:definitions[@targetNamespace='http://api.schenker.pl/TransportOrders/']/wsdl:binding[@name='TransportOrdersBinding']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://api.schenker.pl/TransportOrders/']/wsdl:service[@name='TransportOrdersService']/wsdl:port[@name='TransportOrdersPort']
Cannot import wsdl:binding
Detail: The given key was not present in the dictionary.
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://api.schenker.pl/TransportOrders/']/wsdl:binding[@name='TransportOrdersBinding']

Is there any possibility that I can add that WSDL to .NET Standard as Web Reference? Or it's a problem of that Schenker service that is only compatible with old .NET Framework?

Why it's a problem, because I need to host target application od linux machine.

WSDL file: https://pastebin.com/p0nrLiwe

TransportOrderds.xsd https://pastebin.com/w6Edzdjz

StandardTypes.xsd https://pastebin.com/0pu6YJuA

1 Answers

You can try two options here except Connected Services.

Options 1 - Try to consume the WSDL with similar to the service model metadata, using dotnet-svcutil. This is a command-line tool to generate web service references for .NET Core and .NET Standard. Reference for dotnet-svcutil

Option 2 - Use the channel factory to consume WCF service. The drawback of this option is you should know about the contract definition of the WCF service you would like to consume. I created a small WCF service and tried it out, it was less trouble making method.

I defined the known WCF contract in the ASP.NET Core MVC project, as shown below,

using System.ServiceModel;

namespace AspNet_Core_Wcf_Client.Contracts
{
    [ServiceContract]
    public interface IOrderService
    {
        [OperationContract]
        int GetOrdersCount();
    }
}

This contract defined in my WCF as well.

Then consumed the this service from the controller as shown below.

using AspNet_Core_Wcf_Client.Contracts;
using Microsoft.AspNetCore.Mvc;
using System.ServiceModel;

namespace AspNet_Core_Wcf_Client.Controllers
{
    public class OrderController : Controller
    {
        public IActionResult Index()
        {
            // create binding object
            BasicHttpBinding binding = new BasicHttpBinding();

            // create endpoint object
            EndpointAddress endpoint = new EndpointAddress("http://localhost:64307/OrderService.svc");

            // create channel object with contract
            ChannelFactory<IOrderService> channelFactory = new ChannelFactory<IOrderService>(binding, endpoint);

            // Create a channel
            IOrderService client = channelFactory.CreateChannel();
            int result = client.GetOrdersCount();

            ViewBag.Count = result;

            return View();
        }
    }
}

To use successfully channel factory method needs to install ServiceModel from nugget packages.

Related