如何解决netstandard2.0中的WCF通信不支持IServiceBehavior和其他类
我有一组用WCF编写的服务。 这是一个完整的逻辑,无法更改并重写为另一种技术。
我想在.NET Core 2.1中创建一个应用程序并连接到WCF服务。我正在使用的库具有用于自定义通信,绑定,终结点行为等所有服务的客户端。此库是用.NET Framework v4.7.2编写的,因此如果要在.NET Core应用程序中使用它,则需要添加目标.net标准2.0。
我这样做了,但现在出现问题,因为.netstandard2.0不支持某些类。
public class UserInfoBehavior : Attribute,IServiceBehavior,IEndpointBehavior
{}
例如,上述类用于将EndpointBehaviors添加到我的频道:
public DashboardServiceClient(InstanceContext instanceContext,string endpointConfigurationName,string endpointAddress)
: base(instanceContext,endpointConfigurationName,endpointAddress)
{
base.ChannelFactory.Endpoint.EndpointBehaviors.Add(new UserInfoBehavior());
}
问题在于,在.netstandard 2.0中IServiceBehavior不可用。您知道与此等效吗?我正在使用其他类,但不支持这些类:
- RemoteEndpointMessageProperty,
- ClientBase中的方法Open(),
- Channeldispatcher,
- 还有Endpointdispatcher,它是System.ServiceModel.dispatcher中的空类
我想知道是否可以将其定位为netstandard
解决方法
您可以通过添加连接的引用来调用wcf服务。 选择WCF Web服务引用提供程序。 输入您的WCF服务URI: 检查所有报价并完成。 您可以在客户端中看到此文件夹。
只需在客户端中调用它,您就可以在WCF服务中访问该方法。
static void Main(string[] args)
{
ServiceReference2.Service1Client service1Client = new ServiceReference2.Service1Client();
var t=service1Client.GetDataAsync(15);
Console.WriteLine(t.Result);
Console.ReadKey();
}
您也可以参考以下链接来调用wcf服务: Use the WCF Web Service Reference Provider Tool
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。