You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description: ServiceModel.Channels.TextEncoderDefaults.ValidateEncoding throw ArgumentException with 'shift_jis' Maui.net (android),reported encountering an exception while trying to use a WCF client in MAUI .NET: System.ArgumentException: テキスト メッセージ形式に使用されているテキスト エンコード ‘shift_jis’ はサポートされていません。 (Parameter ‘encoding’)
Double reviewing the relevant code in ServiceModel.Channels.TextEncoderDefaults.ValidateEncoding, which indicates that only UTF8, Unicode, and BigEndianUnicode encodings are supported . The encoding the customer is using is shift_jis(a character encoding for the Japanese language).
Hello, JiakaiDou
Sorry, but I think the problem is not that simple.
I have commented the 'shift_jis' source code that register the japanese encoding
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseSkiaSharp()
.UseMauiCommunityToolkit()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
builder.Services.AddSingleton<MainPage>();
// commented here to avoid
// System.ArgumentException: テキスト メッセージ形式に使用されている
// テキスト エンコード ‘shift_jis’ はサポートされていません。 (Parameter ‘encoding’)
//ShiftJisEncoding.RegisterShiftJis(); (Line 34)
return builder.Build();
}
}
The BasicHttpBinding() worked without problems in this way.
My old wcf service not have reference to 'shift_jis' encoding.
But, what is the relationship between EncodingProvider' class and the "BasicHttpBinding" class ? (I have commented the line 34 of MauiProgram.cs)
Even so, the wcf client (android) failed when connecting to the server ("Connection failure")
The Windows version does not fail, it connects and returns the data.
My conclusion is that Maui.net (Android) is not WCF compatible. Is this right? (NO)
Correction :
After append in "AndroidManifest.xml" in the <application android:allowBackup="true" ... /> element an 'android:usesCleartextTraffic = "true"'
public class ShiftJisEncoding : EncodingProvider
{
public static void RegisterShiftJis()
{
try
{
ShiftJisEncoding jap = new ShiftJisEncoding();
Encoding.RegisterProvider(jap);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
}
public ShiftJisEncoding()
{
}
static private Encoding jp;
public override Encoding? GetEncoding(string name, EncoderFallback encoderFallback, DecoderFallback decoderFallback)
{
return base.GetEncoding(name, encoderFallback, decoderFallback);
}
public override Encoding GetEncoding(int codepage)
{
if (jp is null)
{
jp = CodePagesEncodingProvider.Instance.GetEncoding(codepage);
}
return jp;
}
public override Encoding GetEncoding(string name)
{
if (jp is null)
{
jp = CodePagesEncodingProvider.Instance.GetEncoding(name);
}
return jp;
}
}
PPS: "Connection failure" can be a better error message, even when debugging; for example, adding this
Try append in "AndroidManifest.xml" in the <application android:allowBackup="true" ... /> element an 'android:usesCleartextTraffic = "true"' in your AndroidManifest.xml
Community Feedback: ServiceModel.Channels.TextEncoderDefaults.ValidateEncoding throw ArgumentException with 'shift_jis' Maui.net (android) - Developer Community
Description: ServiceModel.Channels.TextEncoderDefaults.ValidateEncoding throw ArgumentException with 'shift_jis' Maui.net (android),reported encountering an exception while trying to use a WCF client in MAUI .NET: System.ArgumentException: テキスト メッセージ形式に使用されているテキスト エンコード ‘shift_jis’ はサポートされていません。 (Parameter ‘encoding’)
Double reviewing the relevant code in ServiceModel.Channels.TextEncoderDefaults.ValidateEncoding, which indicates that only UTF8, Unicode, and BigEndianUnicode encodings are supported . The encoding the customer is using is shift_jis(a character encoding for the Japanese language).
Ref: Shift JIS - Wikipedia
The text was updated successfully, but these errors were encountered: