Reputation: 1271
I'm building an asp.net core 2.1 web application and I need to call an old net.tcp endpoint in order to get details about a booking. The endpoint is configured like so in the web.config of another old application:
<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>
In aspnet core I believe can't use this file based configuration, but need to do it programmatically. I've tried using svcutil to generate a service reference, but this does not work with the net.tcp service.
I've tried to call setup a web.config file with the above configuration and call the endpoint like this
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;
}
But it throws an exception
System.PlatformNotSupportedException: Configuration files are not supported.
How do I go about this?
I would be grateful for any advice you can give.
Upvotes: 3
Views: 6740
Reputation: 1271
So it turned out to be quite simple. I found this post How to programmatically connect a client to a wcf service
Easy.
Upvotes: 1