TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Clemens Linders
NA
2
685
Problem deleting a record using an ODATA webservice
Mar 26 2020 5:02 AM
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 availabale. The web services are created automatically, so there cannot be an error in that part.
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.
private void button4_Click(object sender, EventArgs e)
{//delete
string _wsURL = "https://api.businesscentral.dynamics.com/v2.0/SomeFunkyGUID/Sandbox/WS/CRONUS%20NL/Page/WorkersWS";
string _userName = "UserName";
string _wsKey = "Password";
//Create an instance of the D365BC SOAP WS
BasicHttpBinding _binding = new BasicHttpBinding();
//Set https usage
_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); //this textbox holds this: W/ABC12345 nr which is like a primary key
}
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):
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);//this textbox holds this: W/ABC12345 nr which is like a primary key
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
Reply
Answers (
1
)
WPF Carousel Demo
Unable to get files/ folder under C:\windows\system32\OObe