1

hi I am trying to implement webhook receiver on our end in WebApi2.as per webhook sender docs they will send encrypted stream ( check doc below for more clarification ).

The encrypted payload is stored in the body of the message as a stream of bytes. The decrypted payload is encoded as unicode/UTF-16LE.

so I implement a action on controller and set byte[] as a input for method check implementation below

    [AllowAnonymous]
    [ActionName(LiquidityProvider.BC)]
    [Route("api/webhooks/incoming/bc")]
    [HttpPost]
    public async Task<IHttpActionResult> BCWebhook(byte[] bytes)
    {
        try
        {
            Utility.Log("i am in");
            await WebhookService.ExecuteWebook(LiquidityProvider.BC, bytes);
        }
        catch (Exception ex)
        {
            Utility.LogWebhooks(ex.ToString());
        }

        // do whatever you want to do with payload and return OK.
        return Ok();
    }

but i am getting error on model state which says Unable to translate bytes [B9] at index 2 from specified code page to Unicode.

exception in detail

[{"propertyName":"bytes","errorMessage":"","exception":{"ClassName":"System.Text.DecoderFallbackException","Message":"Unable to translate bytes [B9] at index 2 from specified code page to Unicode.","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":" at System.Text.DecoderExceptionFallbackBuffer.Throw(Byte[] bytesUnknown, Int32 index)\r\n at System.Text.DecoderExceptionFallbackBuffer.Fallback(Byte[] bytesUnknown, Int32 index)\r\n at System.Text.DecoderFallbackBuffer.InternalFallback(Byte[] bytes, Byte* pBytes, Char*& chars)\r\n at System.Text.UTF8Encoding.GetChars(Byte* bytes, Int32 byteCount, Char* chars, Int32 charCount, DecoderNLS baseDecoder)\r\n at System.Text.DecoderNLS.GetChars(Byte[] bytes, Int32 byteIndex, Int32 byteCount, Char[] chars, Int32 charIndex, Boolean flush)\r\n at System.Text.DecoderNLS.GetChars(Byte[] bytes, Int32 byteIndex, Int32 byteCount, Char[] chars, Int32 charIndex)\r\n at System.IO.StreamReader.ReadBuffer(Char[] userBuffer, Int32 userOffset, Int32 desiredChars, Boolean& readToUserBuffer)\r\n at System.IO.StreamReader.Read(Char[] buffer, Int32 index, Int32 count)\r\n at Newtonsoft.Json.JsonTextReader.ReadData(Boolean append, Int32 charsRequired)\r\n at Newtonsoft.Json.JsonTextReader.ReadNullChar()\r\n at Newtonsoft.Json.JsonTextReader.ReadAsBytes()\r\n at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":"8\nThrow\nmscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem.Text.DecoderExceptionFallbackBuffer\nVoid Throw(Byte[], Int32)","HResult":-2147024809,"Source":"mscorlib","WatsonBuckets":null,"ParamName":null}]

any idea what may be the issue ?

Muhammad Faisal
  • 155
  • 2
  • 13
  • Could you include the byte array that causes the exception. It may just be the content is not being sent/interpreted correctly. – phuzi Jan 27 '22 at 08:46

0 Answers0