在MacOS中生成.Net Core Soap Web服务代理 [英] Generate .Net Core Soap Webservices Proxy in MacOS
问题描述
我看过ac#教程,讲师使用
添加引用
生成代理
(但他使用的是Windows pc)
我正在使用Mac,并且正在努力生成代理具有相同方法的Web服务,它使用
system.Web.Services
.Net Core中不存在的软件包
我做了很多研究,发现.Net Core中未包含该文件,我尝试将其添加为外部文件,但未成功,
我读了一些文章,告诉您有一种名为WCF的替代方法,但我又一次在Mac上找不到它,所有教程或官方文档都使用Windows,我已经看到它与.exe一起使用,这可以确保我确定,在Mac或其他Linux系统上不存在这个地狱!
有人可以帮忙吗?有任何想法吗 ?备择方案 ?快捷方式?
谢谢您的阅读,直到这里!
我的解决方案基于使用.Net Core CLI,如官方文档此处
- 为您的项目创建一个名为HelloSvcutil的目录,并使其成为当前目录,如以下示例所示:
mkdir HelloSvcutil
cd HelloSvcutil
- 使用dotnet new命令在该目录中创建一个新的C#控制台项目,如下所示:
< blockquote>
dotnet新控制台
-
在编辑器中打开HelloSvcutil.csproj项目文件,编辑Project元素,然后添加 dotnet-svcutil NuGet包a s CLI工具参考,使用以下代码:
< ItemGroup>
< DotNetCliToolReference Include = dotnet-svcutil Version = 1.0。* />
< / ItemGroup>
-
使用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软件包作为软件包引用添加到项目中。
- WCF使用dotnet restore命令打包,如下所示:
dotnet restore
-
在编辑器中打开Program.cs文件,编辑Main()方法,然后替换自动生成的代码,其中包含以下代码来调用Web服务:
static void Main(string [] args)
{
var client = new SayHelloClient();
Console.WriteLine(client.HelloAsync( dotnet-svcutil)。Result);
}
-
使用dotnet run命令运行应用程序,如下所示:
dotnet run
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 Web服务代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!