我有一个 WCF 服务,它是使用.Net框架4.7.
现在我必须使用以下命令以编程方式验证和解析 WCF 服务.Net Core 3.1 Web应用程序 without将 WCF 服务添加为服务参考/添加连接服务中的选项Visual Studio 解决方案资源管理器
我们还可以使用通道工厂来调用WCF服务,这种方法不需要添加服务引用,下面是一个演示:
BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
var address = new EndpointAddress("http://localhost:801/Service1.svc/Service");
var factory = new ChannelFactory<IService1>(basicHttpBinding, address);
IService1 channel = factory.CreateChannel();
channel.GetData(1);
Console.WriteLine(channel.GetData(1));
Console.ReadLine();
在客户端,我们需要有一个ServiceContract:
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
// TODO: Add your service operations here
}
该服务合同与服务器端的服务合同相同。
因为是在core中调用WCF,所以需要添加以下两个包:
如果使用NetTcpBinding,则需要添加以下包:
另外,在core中调用WCF时也有一些限制。您可以参考这个链接:
https://github.com/dotnet/wcf/blob/master/release-notes/SupportedFeatures-v2.1.0.md https://github.com/dotnet/wcf/blob/master/release-notes/SupportedFeatures-v2.1.0.md
如果问题仍然存在,请随时告诉我。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)