【问题标题】:Consume WCF service from .NET Framework in .NET Core在 .NET Core 中从 .NET Framework 使用 WCF 服务
【发布时间】:2021-11-07 10:58:42
【问题描述】:

WCF 服务托管在使用 .NET Framework 编写的本地 VM 上。我需要在 .NET Core 应用程序中使用它。当我尝试通过 Microsoft WCF Web Service Reference Provider

连接它时

选项,我收到这样的警告消息

继续忽略此消息,我只能看到实现 async 的端点。

现在,如果我尝试调用任何异步方法,我会收到此错误。

这就是我实例化它的方式。

public class MotionSimulatorManager
{
public  MotionSimulatorManager()
        {
            try
            {
                var uri = "net.tcp://192.168.184.33:8458/MotionSimulator";

                var endpoint = new EndpointAddress(uri);

                var binding = new NetTcpBinding
                {
                    SendTimeout = new TimeSpan(1, 59, 59),
                    ReceiveTimeout = new TimeSpan(1, 59, 59),
                    MaxBufferPoolSize = int.MaxValue,
                    MaxBufferSize = int.MaxValue,
                    MaxReceivedMessageSize = int.MaxValue,
                    Security = { Mode = SecurityMode.None }
                };

                _motionSimulatorClient = new MotionSimulatorClient(binding, endpoint);

            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }




        public async Task<object> NameSake()
        {
            try
            {
                var res = _motionSimulatorClient.EstopAsync(); //error comes at this point.


                return res;
            }
            catch (Exception e)
            {
                File.WriteAllText("D://CollimatorType.txt", e.StackTrace);
                throw;
            }
        }
}

我该如何解决这个问题?如果需要任何其他详细信息,请告诉我。

提前谢谢..

编辑:

我通过添加使用 WCF 服务并创建我在其他 .NET Core 项目中使用的 .NET Framework 项目的 .NET Framework 项目来引入代理,但是在连接到它时出现此错误。

有人可以帮我吗?

【问题讨论】:

    标签: c# .net wcf .net-core .net-framework-version


    【解决方案1】:

    请检查服务配置是否有正确的绑定配置,如下:

    <service behaviorConfiguration="somebehavior"
             name="somename">
       <endpoint address="" binding="wsHttpBinding" 
                 bindingConfiguration="SomeBinding"
                 name="http" 
                 contract="somecontract" />
       <endpoint address="mex" 
                 binding="mexHttpBinding" 
                 bindingConfiguration=""
                 name="mex" 
                 contract="IMetadataExchange" />
       <host>
          <baseAddresses>
             <add baseAddress="http://localhost:8700/service/"/>
          </baseAddresses>
       </host>
    </service>
    

    此绑定配置为空。然后它采用默认的 wsHttpBinding,这与指定的不同。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-30
      • 2021-09-28
      • 2018-11-17
      • 1970-01-01
      • 2019-10-21
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      相关资源
      最近更新 更多