Skip to content

Commit

Permalink
Merge pull request equinor#1800 from JoelDavidLang/get-version-test
Browse files Browse the repository at this point in the history
Use GetVersion to test the connection to a WITSML server.
  • Loading branch information
steinsiv committed Mar 23, 2023
2 parents 2b549bd + 45c5a4b commit d69ea89
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions Src/Witsml/WitsmlClient.cs
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Security;
using System.Threading.Tasks;
Expand Down Expand Up @@ -324,19 +325,21 @@ public async Task<string> GetFromStoreAsync(string query, OptionsIn optionsIn)

public async Task<QueryResult> TestConnectionAsync()
{
WMLS_GetCapRequest request = new()
WMLS_GetVersionResponse response = await _client.WMLS_GetVersionAsync();
if (string.IsNullOrEmpty(response.Result))
{
OptionsIn = "dataVersion=1.4.1.1"
};
throw new Exception("Error while testing connection: Server failed to return a valid version");
}

WMLS_GetCapResponse response = await _client.WMLS_GetCapAsync(request);
if (response.IsSuccessful())
// Spec requires a comma-seperated list of supported versions without spaces
string[] versions = response.Result.Split(',');

if (!versions.Any(v => v == "1.4.1.1"))
{
return new QueryResult(true);
throw new Exception("Error while testing connection: Server does not indicate support for WITSML 1.4.1.1");
}

WMLS_GetBaseMsgResponse errorResponse = await _client.WMLS_GetBaseMsgAsync(response.Result);
throw new Exception($"Error while testing connection: {response.Result} - {errorResponse.Result}. {response.SuppMsgOut}");
return new QueryResult(true);
}

private void LogQueriesSentAndReceived(string querySent, bool isSuccessful, string xmLReceived = null)
Expand Down

0 comments on commit d69ea89

Please sign in to comment.