This is a more complete answer and may help someone who is trying to call a SOAP service endpoint using .NET Core (.NET Core 2.2) and is struggling to get it working.
For the answer I'm assuming you've already added a Connected Service. If not, please refer to this Microsoft Article
The example below is using a BasicHttpBinding
with an Ntlm
Credential Type (DOMAIN\Username):
public async Task<string> ImportSalesOrder(string jsonString)
{
var binding = new BasicHttpsBinding();
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
var endpoint = new EndpointAddress(_appConfig["endpoint"]);
var client = new eCommIntegrationMgt_PortClient(binding, endpoint);
client.ClientCredentials.UserName.UserName = _appConfig["usernam"];
client.ClientCredentials.UserName.Password = _appConfig["password"];
try
{
var result = await client.ImportSalesOrderAsync(jsonString);
return result.return_value;
}
catch (Exception)
{
throw;
}
}
_appConfig
is a global variable, which is made available via DI (Dependency Injection). You can replace them with hard-coded values if you're not making use of DI. The catch
is redundant here, but you can add your custom error handling/logging.
eCommIntegrationMgt_PortClient
is the client i.e. the Service object where all our endpoints exist.