在 MacOS 中生成 .Net Core Soap Webservices 代理 [英] Generate .Net Core Soap Webservices Proxy in MacOS
问题描述
我看过一个 c# 教程,其中讲师使用
生成代理<块引用>添加引用"
(但他用的是 windows pc)
我正在使用 mac,我正在努力使用相同的方法生成 Web 服务的代理,它使用
生成文件<块引用>系统.Web.服务
.Net Core 中不存在的包
我做了很多研究,发现它没有包含在 .Net Core 中,我尝试将其添加为外部但没有成功,我读了一些文章,说有一种叫做 WCF 的替代品,但我在 mac 上没有找到它,所有教程或官方文档都使用 Windows,我看到它正在使用 .exe,这让我确信,这地狱在 mac 或其他 linux 系统上不存在!
有人可以帮忙吗?有任何想法吗 ?备择方案 ?快捷键?
感谢您阅读到这里!
我的解决方案基于使用 .Net Core CLI,如官方文档中所述 这里
- 为您的项目创建一个名为 HelloSvcutil 的目录并将其设为当前目录,如下例所示:
<块引用>
mkdir HelloSvcutil
cd HelloSvcutil
- 使用 dotnet new 命令在该目录中创建一个新的 C# 控制台项目,如下所示:
<块引用>
dotnet 新控制台
在编辑器中打开 HelloSvcutil.csproj 项目文件,编辑 Project 元素,并添加 dotnet-svcutil NuGet 包作为 CLI 工具参考,使用以下代码:
<DotNetCliToolReference Include="dotnet-svcutil" Version="1.0.*"/></项目组> 使用 dotnet restore 命令恢复 dotnet-svcutil 包,如下所示:
<块引用>
dotnet 还原
- 使用 svcutil 命令运行 dotnet 以生成 Web 服务参考文件,如下所示:(使用您的 Web 服务链接,在我的情况下:http://localhost.com/BanqueWS?wsdl )
<块引用>
dotnet svcutil http://contoso.com/SayHello.svc
他生成的文件保存为HelloSvcutil/ServiceReference1/Reference.cs.dotnet_svcutil 工具还将代理代码所需的相应 WCF 包添加到项目中作为包引用.
- 使用 dotnet restore 命令恢复 WCF 包,如下所示:
<块引用>
dotnet 还原
在编辑器中打开 Program.cs 文件,编辑 Main() 方法,并将自动生成的代码替换为以下代码以调用 Web 服务:
static void Main(string[] args){var client = new SayHelloClient();Console.WriteLine(client.HelloAsync("dotnet-svcutil").Result);}
使用 dotnet run 命令运行应用程序,如下所示:
<块引用>
dotnet 运行
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 !
My solution was based on using .Net Core CLI as in the official documentation here
- Create a directory named HelloSvcutil for your project and make it your current directory, as in the following example:
mkdir HelloSvcutil
cd HelloSvcutil
- Create a new C# console project in that directory using the dotnet new command as follows:
dotnet new console
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>
Restore the dotnet-svcutil package using the dotnet restore command as follows:
dotnet restore
- 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.
- Restore the WCF packages using the dotnet restore command as follows:
dotnet restore
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); }
Run the application using the dotnet run command as follows:
dotnet run
这篇关于在 MacOS 中生成 .Net Core Soap Webservices 代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!