如何在asp.net core 2.1中调用net.tcp服务

3

我正在构建一个asp.net core 2.1 web应用程序,需要调用旧的net.tcp端点来获取有关预订的详细信息。该端点在另一个旧应用程序的web.config中进行了配置:

<system.serviceModel>
<behaviors>
  <endpointBehaviors>
    <behavior name="Behaviors.EndpointBehavior">
      <dataContractSerializer maxItemsInObjectGraph="2147483647" />
    </behavior>
  </endpointBehaviors>
</behaviors>
<bindings>
  <netTcpBinding>
    <binding name="unsecuredLargeTcpBuffer" maxBufferSize="20000000" maxReceivedMessageSize="20000000">
      <readerQuotas maxArrayLength="20000000" maxBytesPerRead="20000000" maxStringContentLength="10000000" />
      <security mode="None" />
    </binding>
  </netTcpBinding>
</bindings>

<client>      
  <endpoint address="net.tcp://us-ap-contoso1:12345/Bookings" binding="netTcpBinding" bindingConfiguration="unsecuredLargeTcpBuffer" behaviorConfiguration="Behaviors.EndpointBehavior" contract="Contoso.Contracts.IBookingService" />     
</client>

在aspnet core中,我认为不能使用基于文件的配置,而是需要通过编程来实现。我尝试使用svcutil生成服务引用,但这不适用于net.tcp服务。我尝试使用上述配置调用设置web.config文件并调用终结点。
public Booking FindBooking(string name, string number)
    {
        var proxy = new BookingSearchServiceProxy();

        try
        {
            var query = new BookingFieldQuery
            {
                BookingNumber = number,
                LastName = name
            };

            Booking booking = proxy.FindSingle(query);

            return booking;
        }
        catch (Exception ex)
        {
            //log here
        }
        finally
        {
            proxy.CloseSafely();
        }

        return null;
    }

但它会抛出异常

System.PlatformNotSupportedException: Configuration files are not supported.

我该如何处理这个问题?

非常感谢您所能提供的任何建议。

1个回答

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接