0
服務器側接口:有關WCF休息返回列表
[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>
返回空字符串永遠!如何返回數據?非常感謝你!
你有什麼例子嗎?對不起我的英文不好