小编Cla*_*pel的帖子

C# Azure:如何从 Microsoft.Azure.ServiceBus.Message 读取正文?

我在Microsoft.Azure.ServiceBus.Message课堂上遇到了麻烦。我想创建一个包含有效负载对象的消息对象,然后从中读回该对象。在我当前的示例中,我什至没有通过真正的 Azure 总线发送消息;我只是在内存中创建它,然后尝试读取它。

我无法弄清楚我应该将消息正文读取为什么类型。我已经尝试过byte[]string以及原始对象类型。在我的所有情况下,我都会收到一条XmlException:“输入源格式不正确”。

有人可以告诉我在编码或解码消息时我做错了什么吗?

    [DataContract]
    public class Thingy
    {
        [DataMember]
        public string Doodad { get; set; }
    }

    private static Message CreateMessage()
    {
        var entityMessage = new Thingy {Doodad = "foobar"};
        var serializedMessageBody = JsonConvert.SerializeObject(entityMessage);
        var contentType = typeof(Thingy).AssemblyQualifiedName;
        var bytes = Encoding.UTF8.GetBytes(serializedMessageBody);
        var message = new Message(bytes) {ContentType = contentType};
        return message;
    }

    [Test]
    public void ReadMessageBytes()
    {
        var message = CreateMessage();
        var body = message.GetBody<byte[]>();
        Console.WriteLine(body);
    }

    [Test]
    public …
Run Code Online (Sandbox Code Playgroud)

c# serialization azure message-bus

4
推荐指数
1
解决办法
9708
查看次数

在C#中,如何在Windows 10中的“区域和语言”下选择“国家或地区”?

我运行的是 Windows 10。当我从开始菜单中打开“区域和语言设置”时,我可以选择“国家或地区”。我正在尝试在 C# 程序中获取该值。

我在丹麦。我尝试将我的国家/地区更改为德国(参见屏幕截图),但我无法获取返回德国的代码。重新启动计算机没有帮助。

我受此线程启发编写了一些代码。

我的代码如下所示(同时尝试各种事情,获取我能想到的所有地区/文化事物):

private static void Main(string[] args)
{
    Thread.CurrentThread.CurrentCulture.ClearCachedData();
    Thread.CurrentThread.CurrentUICulture.ClearCachedData();
    var thread = new Thread(() => ((Action) (() =>
    {
        Console.WriteLine("Current culture: {0}", Thread.CurrentThread.CurrentCulture.Name);
        Console.WriteLine("Current UI culture: {0}", Thread.CurrentThread.CurrentUICulture.Name);
        Console.WriteLine("Installed UI culture: {0}", CultureInfo.InstalledUICulture.Name);
        Console.WriteLine("Current region: {0}", RegionInfo.CurrentRegion.ThreeLetterISORegionName);
        Console.WriteLine("System default LCID: {0}", GetSystemDefaultLCID());
    }))());
    thread.Start();
    thread.Join();
    Console.ReadKey();
}

[DllImport("kernel32.dll")]
private static extern uint GetSystemDefaultLCID();
Run Code Online (Sandbox Code Playgroud)

它输出:

Current culture: en-DK
Current UI culture: en-US
Installed UI culture: en-US
Current region: DNK
System default …
Run Code Online (Sandbox Code Playgroud)

c# country culture locale region

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×2

azure ×1

country ×1

culture ×1

locale ×1

message-bus ×1

region ×1

serialization ×1