与SCF服务集成引发'EndpointNotFoundException'异常-ASP .Net Core 2.1

时间:2018-11-05 11:41:35

标签: c# .net wcf core

我尝试与.net标准2.0项目中的WCF服务集成,并且收到以下异常:

{System.ServiceModel.EndpointNotFoundException: There was no endpoint listening at https://X.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

我检查了端点,它是正确的,我尝试手动初始化绑定:

var wsHttpBinding = new BasicHttpsBinding();
wsHttpBinding.TextEncoding = Encoding.Default;
wsHttpBinding.ReaderQuotas = XmlDictionaryReaderQuotas.Max;
wsHttpBinding.Security.Mode = BasicHttpsSecurityMode.Transport;
wsHttpBinding.ReceiveTimeout = TimeSpan.FromSeconds(10000);
wsHttpBinding.MaxBufferPoolSize = 50000000;
wsHttpBinding.MaxReceivedMessageSize = 50000000;
wsHttpBinding.ReaderQuotas.MaxStringContentLength = 50000000;
wsHttpBinding.ReaderQuotas.MaxArrayLength = 50000000;
wsHttpBinding.ReaderQuotas.MaxNameTableCharCount = 50000000;

谢谢

1 个答案:

答案 0 :(得分:0)

通常,在Asp.net核心项目中调用Web服务有两种方法。

  1. 添加服务引用以调用服务。
  2. 使用Channel Factory生成服务实例以调用该方法。

无论使用哪种方法,我们都需要指定服务端点,以便我们可以找到服务所在的位置。 现在,最新的NetCore项目使用Microsoft WCF WEB服务参考提供程序工具来添加服务参考,就像NetFramework项目中的一样。 enter image description here
这是有关操作方法的正式文件。
https://docs.microsoft.com/en-us/dotnet/core/additional-tools/wcf-web-service-reference-guide
Github
https://github.com/dotnet/wcf/blob/master/release-notes/WCF-Web-Service-Reference-notes.md
在这种特定情况下,生成的ConnectedService文件将包含服务端点。 enter image description here
如果我们使用ChannelFactory来调用服务。您可以参考以下代码。

Uri uri = new Uri("http://localhost:9001/service1.svc");
            BasicHttpBinding binding = new BasicHttpBinding();
            ChannelFactory<IService1> factory = new ChannelFactory<IService1>(binding, new EndpointAddress(uri));
            IService1 service = factory.CreateChannel();
            var result = service.GetData(100);

请随时告诉我是否有什么可以帮助的