的服務如何顯示Unicode代替「????」在WCF Web服務
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(類)
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";
}
}
}
}
訪問類 的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();
}
}
}
我使用的是Visual Studio 2008,我是C#的新手。 當我運行的Program.cs的情況下,輸出我選擇語言CH(中國)或ja(日文)如下:
輸入你的名字: 布魯斯 輸入你的語言: JA
? ???布魯斯(而不是こんにちは布魯斯)
http://forums.asp.net/t/1481581.aspx?Unicode+characters+becoming+ – user1519979 2014-09-11 10:46:27
'Console.OutputEncoding = System.Text.Encoding.UTF8;' – 2014-09-11 10:49:41