我想在.NET Standard项目(Visual Studio 2017)中执行“添加服务引用”操作。
为了使WCF访问成为可能,我已经在NuGet中安装了“System.ServiceModel.Http”和“System.ServiceModel.Security”。
然而,在.NET Standard项目中没有“添加服务引用”菜单项。我该如何添加服务引用?
它存在于.NET Framework项目中,但不存在于.NET Standard项目中,所以有些麻烦。
我想在.NET Standard项目(Visual Studio 2017)中执行“添加服务引用”操作。
为了使WCF访问成为可能,我已经在NuGet中安装了“System.ServiceModel.Http”和“System.ServiceModel.Security”。
然而,在.NET Standard项目中没有“添加服务引用”菜单项。我该如何添加服务引用?
它存在于.NET Framework项目中,但不存在于.NET Standard项目中,所以有些麻烦。
Visual Studio 2017 Community v15.9.7
解决方案资源管理器 -> 右键点击 依赖项 -> 添加 连接的服务
截图:
这个练习基于使用WCF Web服务引用提供程序工具
环境:
我已经使用了asmx web服务,但文档说:它与WCF服务相同。我认为它适用于所有SOAP服务。
1)添加服务引用的步骤:
项目 > 添加连接的服务
将WCF服务引用添加到项目中。
现在生成服务客户端代理,有几种方法可以实现,其中一种方法是使用svcutil,例如,在VS命令提示符中运行以下命令以生成客户端代理类。
svcutil -out:c:\temp\ClientProxy.cs https://[YourWebServiceDomain]/[Service].svc
将上面的ClientProxy.cs文件复制到您的项目中,放在assets下的任意位置。
using UnityEngine;
using System.ServiceModel;
using YourClientProxyNamespace;
public class WebClient : MonoBehavior
{
void Start()
{
using (ProxyClient client = new ProxyClient(
new BasicHttpBinding(BasicHttpSecurityMode.Transport),
new EndpointAddress("https://YourWebServiceDomain/Service.svc")))
{
var response = client.DesiredMethod();
// Do whatever with the response
}
}
}
你可以通过将服务拖入 bin 目录来手动添加它。