服务器端接口:
[OperationContract]
[WebGet(UriTemplate = "GetCardInfoByCardNumber/?cardNumber={cardNumber}&SerialNumber={SerialNumber}&token={token}", ResponseFormat = WebMessageFormat.Json)]
IList<Cards> GetCardInfoByCardNumber(string cardNumber, string SerialNumber, string token);
服务器端实现:
public IList<Cards> GetCardInfoByCardNumber(string cardNumber, string SerialNumber, string token)
{
if (BaseClass.HasPermission(token))
return cm.GetCardInfoByCardNumber(cardNumber, SerialNumber);
else
return null;
}
客户端:
class Program
{
static void Main(string[] args)
{
TestResWCF();
Console.ReadLine();
}
static List<Cards> TestResWCF()
{
List<Cards> a = null;
string ServiceUri = "http://192.168.15.18:8089/GetCardInfoByCardNumber/?cardNumber=HH-120109-017&SerialNumber=&token=123456";
WebClient proxy = new WebClient();
proxy.Encoding = Encoding.UTF8;
proxy.DownloadStringCompleted += new DownloadStringCompletedEventHandler
(
(s, e) =>
{
Stream stream = new MemoryStream(Encoding.Unicode.GetBytes(e.Result));
DataContractJsonSerializer obj = new DataContractJsonSerializer(typeof(List<Cards>));
a = obj.ReadObject(stream) as List<Cards>;
}
);
proxy.DownloadStringAsync(new Uri(ServiceUri));
return a;
}
List<Cards>
总是返回空字符串!如何返回数据?非常感谢!
你有什么例子吗?对不起,我的英语不好