Click here to Skip to main content
15,039,244 members
Home / Discussions / C#
   

C#

 
GeneralRe: problem registering in the access database Pin
Richard MacCutchan17-Mar-20 2:18
mveRichard MacCutchan17-Mar-20 2:18 
GeneralRe: problem registering in the access database Pin
ago248617-Mar-20 2:26
Memberago248617-Mar-20 2:26 
GeneralRe: problem registering in the access database Pin
Richard MacCutchan17-Mar-20 2:36
mveRichard MacCutchan17-Mar-20 2:36 
QuestionJava Api Callbacks crashes on dotnet framework version 4.5 and above Pin
isaketranjan16-Mar-20 0:06
Memberisaketranjan16-Mar-20 0:06 
AnswerRe: Java Api Callbacks crashes on dotnet framework version 4.5 and above Pin
Gerry Schmitz16-Mar-20 5:05
mveGerry Schmitz16-Mar-20 5:05 
QuestionC# and ODATA CRUD communication with D365BC web service Pin
clemenslinders12-Mar-20 0:13
Memberclemenslinders12-Mar-20 0:13 
SuggestionRe: C# and ODATA CRUD communication with D365BC web service Pin
Richard Deeming12-Mar-20 1:12
mveRichard Deeming12-Mar-20 1:12 
GeneralRe: C# and ODATA CRUD communication with D365BC web service Pin
clemenslinders12-Mar-20 3:48
Memberclemenslinders12-Mar-20 3:48 
Hi Richard,

Thanks for your reply.

If I used the code you profided me but I cannot pass 'data' to _client as it expects a class and not Json data.

If I create a class and fill it, like in the MS Docs page you provided, than I get error 401 not authorized.

WorkersClass _data = new WorkersClass();
_data.E_Tag = string.Empty;
_data.No = tbNo.Text;
_data.First_name = tbFirstName.Text;
_data.Last_Name = tbLastName.Text;
_data.FunctionName = tbFunctionName.Text;

var url = await CreateWorkerAsync(_data);


static async Task<Uri> CreateWorkerAsync(WorkersClass _worker)
{
    string _url = "https://api.businesscentral.dynamics.com/v2.0/SomeFunkyGuid/Sandbox/ODataV4/Company('CRONUS%20NL')/WorkersWebService";//Card Page
    string _userName = "UserName";
    string _wsKey = "Password";
    _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(_userName, _wsKey);
    HttpResponseMessage response = await _client.PostAsJsonAsync(_url, _worker);
    response.EnsureSuccessStatusCode();

    // return URI of the created resource.
    return response.Headers.Location;
}


I tried the following:
var body = new
{
    E_Tag = string.Empty,     // Unique key
    No = tbNo.Text,
    First_name = tbFirstName.Text,
    Last_Name = tbLastName.Text,
    FunctionName = tbFunctionName.Text,
};


string json = JsonConvert.SerializeObject(body);
byte[] data = Encoding.UTF8.GetBytes(json);

var url = await CreateWorkerAsync(data);


The error I get is: Argument 1: cannot convert from byte[] to WorkersClass.

If I look at _client.PostAsJsonAsync, than I don't see a other solution where it says I can pass Json data?

I feel that I am close, but I think I miss the final step.

Hope you can help me.


Kind regards,



Clemens Linders
GeneralRe: C# and ODATA CRUD communication with D365BC web service Pin
Richard Deeming12-Mar-20 4:29
mveRichard Deeming12-Mar-20 4:29 
GeneralRe: C# and ODATA CRUD communication with D365BC web service Pin
clemenslinders12-Mar-20 4:54
Memberclemenslinders12-Mar-20 4:54 
GeneralRe: C# and ODATA CRUD communication with D365BC web service Pin
Richard Deeming12-Mar-20 5:43
mveRichard Deeming12-Mar-20 5:43 
GeneralRe: C# and ODATA CRUD communication with D365BC web service Pin
clemenslinders12-Mar-20 21:25
Memberclemenslinders12-Mar-20 21:25 
QuestionC# code -Compare 2 pdf and give output as 2 pdfs with color Pin
Member 1476942610-Mar-20 20:13
MemberMember 1476942610-Mar-20 20:13 
AnswerRe: C# code -Compare 2 pdf and give output as 2 pdfs with color Pin
OriginalGriff10-Mar-20 20:49
mveOriginalGriff10-Mar-20 20:49 
AnswerRe: C# code -Compare 2 pdf and give output as 2 pdfs with color Pin
Maciej Los10-Mar-20 21:25
mveMaciej Los10-Mar-20 21:25 
JokeRe: C# code -Compare 2 pdf and give output as 2 pdfs with color Pin
Richard Deeming11-Mar-20 0:37
mveRichard Deeming11-Mar-20 0:37 
GeneralRe: C# code -Compare 2 pdf and give output as 2 pdfs with color Pin
Member 798912212-Mar-20 3:01
MemberMember 798912212-Mar-20 3:01 
Questiontime requirements in real-times systems? Pin
auting8210-Mar-20 3:08
Memberauting8210-Mar-20 3:08 
AnswerRe: time requirements in real-times systems? Pin
OriginalGriff10-Mar-20 3:49
mveOriginalGriff10-Mar-20 3:49 
GeneralRe: time requirements in real-times systems? Pin
auting8210-Mar-20 4:43
Memberauting8210-Mar-20 4:43 
GeneralRe: time requirements in real-times systems? Pin
OriginalGriff10-Mar-20 4:51
mveOriginalGriff10-Mar-20 4:51 
AnswerRe: time requirements in real-times systems? Pin
Gerry Schmitz10-Mar-20 6:30
mveGerry Schmitz10-Mar-20 6:30 
AnswerRe: time requirements in real-times systems? Pin
Richard MacCutchan10-Mar-20 7:02
mveRichard MacCutchan10-Mar-20 7:02 
Questionimport multiple csv files into msql database - C# coding - reg Pin
Member 137889379-Mar-20 7:28
MemberMember 137889379-Mar-20 7:28 
AnswerRe: import multiple csv files into msql database - C# coding - reg Pin
phil.o9-Mar-20 8:25
mvephil.o9-Mar-20 8:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.