Generate .Net Core Soap Webservices Proxy in MacOS

2019-08-26 07:57发布

问题:

I have seen a c# tutorial where the instructor generates the proxy using

"Add reference "

(but he was using windows pc )

I am using a mac and I am struggling generate the proxy of a web-service with the same approach, It generates files with

system.Web.Services

a package which isn't existing in the .Net Core

I did many researches and I found that isn't included in the .Net Core, i try to add it as an externally but didn't succeed, I read some articles telling that there is an alternative called WCF, but again I didn't found it on mac, all tutorials or official documentation uses windows, I've seen that is working with a .exe which make me sure, this hell isn't existing on mac or other linux systems !

Some can help ? any ideas ? alternatives ? shortcuts ?

Thank you to read it until here !

回答1:

You could try to install Microsoft WCF Web Service Reference Provider for VS 2017. You could follow the part “how to use the extension” to generate the client code, then copy and paste the generated code to your VS Code project.

Dot Net core is all about rest, not SOAP



回答2:

As adding Microsoft WCF Web Service Reference does not work for ASP.NET Core 2.1 project at the moment, you can add new .NET Standard class library project targeted to Standard 2.0 and add service reference to it:

  1. Right click on project
  2. Select Add -> Connected Service
  3. In Connected Services window select Microsoft WCF Web Service Reference Provider
  4. Specify WSDL details as described the the guide
  5. Add new library reference to your ASP.NET Core web application (targeted to .NET Core 2.1)


回答3:

My solution was based on using .Net Core CLI as in the official documentation here

  1. Create a directory named HelloSvcutil for your project and make it your current directory, as in the following example:

mkdir HelloSvcutil

cd HelloSvcutil

  1. Create a new C# console project in that directory using the dotnet new command as follows:

dotnet new console

  1. Open the HelloSvcutil.csproj project file in your editor, edit the Project element, and add the dotnet-svcutil NuGet package as a CLI tool reference, using the following code:

    <ItemGroup>
        <DotNetCliToolReference Include="dotnet-svcutil" Version="1.0.*" />
    </ItemGroup>
    
  2. Restore the dotnet-svcutil package using the dotnet restore command as follows:

dotnet restore

  1. Run dotnet with the svcutil command to generate the web service reference file as follows: (use your web-service link, in my case : http://localhost.com/BanqueWS?wsdl )

dotnet svcutil http://contoso.com/SayHello.svc

he generated file is saved as HelloSvcutil/ServiceReference1/Reference.cs. The dotnet_svcutil tool also adds to the project the appropriate WCF packages required by the proxy code as package references.

  1. Restore the WCF packages using the dotnet restore command as follows:

dotnet restore

  1. Open the Program.cs file in your editor, edit the Main() method, and replace the auto-generated code with the following code to invoke the web service:

    static void Main(string[] args)
    {
       var client = new SayHelloClient();
       Console.WriteLine(client.HelloAsync("dotnet-svcutil").Result);
    }
    
  2. Run the application using the dotnet run command as follows:

dotnet run