2023 Jun 02 12:37 PM
Use the following code. It tries to connect to a non-existent SAP system via the newly supported WebSocket approach and invoke RFC_PING:
internal sealed class TestDestinationConfiguration : IDestinationConfiguration
{
public RfcConfigParameters GetParameters(string destinationName)
{
var configParams = new RfcConfigParameters();
configParams[RfcConfigParameters.Name] = "...";
configParams[RfcConfigParameters.SystemID] = "...";
configParams[RfcConfigParameters.SystemNumber] = "..";
configParams[RfcConfigParameters.Client] = "...";
configParams[RfcConfigParameters.Language] = "..";
configParams[RfcConfigParameters.User] = "...";
configParams[RfcConfigParameters.Password] = "...";
configParams[RfcConfigParameters.WebsocketHost] = "doesnotexist";
configParams[RfcConfigParameters.WebsocketPort] = "...";
return configParams;
}
public bool ChangeEventsSupported() => false;
public event RfcDestinationManager.ConfigurationChangeHandler ConfigurationChanged;
}
internal static class Program
{
private static void Main()
{
RfcDestinationManager.RegisterDestinationConfiguration(new TestDestinationConfiguration());
var destination = RfcDestinationManager.GetDestination("...");
var repository = destination.Repository;
var pingFunction = repository.CreateFunction("RFC_PING");
pingFunction.Invoke(destination);
}
}
That fails with:
Unhandled Exception: System.InvalidOperationException: The operation is not allowed on non-connected sockets.
at System.Net.Sockets.TcpClient.GetStream()
at SAP.Middleware.Connector.TcpDriver.ConnectAsClient(Dictionary`2 options, Boolean forRepository)
at SAP.Middleware.Connector.WebSocketClientDriver.ConnectAsClient(Dictionary`2 options, Boolean forRepository)
at SAP.Middleware.Connector.RfcConnection.ConnectAsClient(RfcDestination destination, Boolean forRepository)
at SAP.Middleware.Connector.RfcConnectionPool..ctor(RfcDestination destination, Boolean forRepositoryCalls)
at SAP.Middleware.Connector.RfcConnectionPool.GetPool(RfcDestination destination, Boolean forRepository, Boolean create)
at SAP.Middleware.Connector.RfcDestination.GetClient(Boolean forRepository)
at SAP.Middleware.Connector.RfcDestination.SetAttributeValues()
at SAP.Middleware.Connector.RfcDestination.get_SystemAttributes()
at SAP.Middleware.Connector.RfcRepository.GetRepositoryForDestination(RfcDestination destination)
at SAP.Middleware.Connector.RfcDestination.get_Repository()
at SampleSAPWebSocketClient.Program.Main()
The issue is in TcpDriver.ConnectAsClient, which does not check the result of the asynchronous operation tcpSocket.BeginConnect and always proceeds as if the connection was established successfully.
Please fix as it is pretty hard to diagnose connection failures when the underlying errors are swallowed by NCo.
Thanks!
2023 Jun 02 12:38 PM
Hello Thomas,
Welcome to the SAP Community! Thank you for visiting us to get answers to your questions.
Since you're asking a question here for the first time, I'd like to offer some friendly advice on how to get the most out of your community membership and experience.
First, please see https://community.sap.com/resources/questions-and-answers, as this resource page provides tips for preparing questions that draw responses from our members. Secondly, feel free to take our Q&A tutorial at https://developers.sap.com/tutorials/community-qa.html as well, as that will help you when submitting questions to the community.
Finally, I recommend that you include a profile picture. By personalizing your profile, you encourage readers to respond: https://developers.sap.com/tutorials/community-profile.html.
I hope you find this advice useful, and we're happy to have you as part of SAP Community!
Best regards,
Anne