简体   繁体   English

在WCF Web服务中如何显示Unicode代替“ ????”

[英]How to show Unicode in place of “????” in WCF web services

The Service 服务

ISayHello.cs (interface) ISayHello.cs(接口)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace MyWCFService
{
    [ServiceContract]
    public interface IHelloService
    {
        [OperationContract]
        string SayHello(String name, String language);
    }
}

SayHello.cs (class) SayHello.cs (类)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace MyWCFService
{   
    public class HelloService : IHelloService
    {
        public string SayHello(String name, String language)
        {
            switch (language)
            {
                case "en":
                    return "Hello " + name;

                case "ja":
                    return "こんにちは " + name;

                case "ch":
                    return "您好 " + name;

                case "es":
                    return "Hola " + name;

                default:
                    return "Unsupported Language";
            }
        }
    }
}

Accessing Class Program.cs 访问类 Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
namespace WCFServiceTester
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter your name: ");
            string name = Console.ReadLine();
            Console.WriteLine("Enter your language: ");
            string lang = Console.ReadLine();

            HelloServiceClient hsc = new HelloServiceClient();
            Console.WriteLine(hsc.SayHello(name, lang));
            Console.ReadKey();
        }
    }
}

I am using Visual Studio 2008 and I'm new with C#. 我正在使用Visual Studio 2008,并且是C#的新手。 When I am running program.cs the output in case I choose language ch(chinese) or ja(japanese) is as follows : 当我运行program.cs时,如果我选择语言ch(chinese)或ja(japanese),则输出如下:

enter your name : Bruce enter your language : ja 输入您的姓名:布鲁斯输入您的语言:ja

???? ???? Bruce (instead of こんにちは Bruce) 布鲁斯(代替布鲁斯)

Your code should support UNICODE just fine. 您的代码应支持UNICODE。 Your Console Font that's printing it, is not. 您正在打印的控制台字体不是。 At least not by default. 至少不是默认情况下。 Switch your Console to a UNICODE font. 将您的控制台切换为UNICODE字体。

Console.OutputEncoding = System.Text.Encoding.Unicode

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM