LS,
In D365BC I created a simple table, card page and list page. You can create a list of workers entering: first name, last name and function.
I turned the card page into a web service and now there is a ODATA V3, ODATA V4 and SOAP web service available.
In C# VS2019 I created a program to see if I can delete a record using these web services.
When I use the SOAP webservice, there is no problem. It deletes the selected record.
But when I use the ODATA web service I get error 404 not found.
What I have tried:
When I use this code for the the SOAP webservice, there is no problem. It deletes the selected record.
private void button4_Click(object sender, EventArgs e)
{
string _wsURL = "https://api.businesscentral.dynamics.com/v2.0/SomeFunkyGUID/Sandbox/WS/CRONUS%20NL/Page/WorkersWS";
string _userName = "UserName";
string _wsKey = "Password";
BasicHttpBinding _binding = new BasicHttpBinding();
_binding.Security.Mode = BasicHttpSecurityMode.Transport;
_binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
WorkersWS_PortClient _ws = new WorkersWS_PortClient(_binding, new EndpointAddress(_wsURL));
_ws.ClientCredentials.UserName.UserName = _userName;
_ws.ClientCredentials.UserName.Password = _wsKey;
try
{
_ws.Delete(rtbE_Tag.Text);
}
catch (Exception _ex)
{
}
}
But now I do almost the same, except that I now use the ODATA web service (PS there is no difference if I use the ODATA v3 or v4 web service, they both give error 404 not found):
private async void button6_Click(object sender, EventArgs e)
{
try
{
string _url = "https://api.businesscentral.dynamics.com/v2.0/SomeFunkyGuid/Sandbox/ODataV4/Company('CRONUS%20NL')/WorkersWS";
string _userName = "UserName";
string _wsKey = "Password";
byte[] _authenticationParameter = Encoding.UTF8.GetBytes(_userName + ":" + _wsKey);
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(_authenticationParameter));
HttpResponseMessage response = await _client.DeleteAsync(_url + "/" + rtbE_Tag.Text);
response.EnsureSuccessStatusCode();
}
catch (Exception ex)
{
}
}
When I use the code to try using the ODATA web service the code breaks at: response.EnsureSuccessStatusCode();
The error is: Statuscode no success, 404 (not found)
Perhaps I am passing the record that is to be deleted in a wrong way?
I hope someone can help me.
Kind regards,
Clemens Linders