从WCF数据服务中读取pdf

时间:2013-07-12 07:46:08

标签: wcf-data-services silverlight-5.0

我添加了一个WCF数据服务,如:

[WebGet]
public byte[] GetPdf(int id)
{
...
return result;
}

当我从浏览器调用时

http://localhost:50300/data/MyService/GetPdf?id=114

我收到的回复如下:

<?xml version="1.0" encoding="UTF-8"?>
<d:GetPdf m:type="Edm.Binary"
 xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
 xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">JVBERi0xLjQNCiXi48/TDQolDQold1BERjMgYnkgV1
 ...</d:GetPdf>

然后我尝试用

读取silverlight客户端中的字节
 private void ReadPdf()
    {
        Uri uri = new Uri("http://localhost:50300/data/MyService/GetPdf?id=114");
        var myQuery = client.BeginExecute(uri, MyCallback, null, "GET", null);
    }

和MyCallback

  public void MyCallback(IAsyncResult result)
  {
     ???
  }

结果我得到一个System.Data.Services.Client.QueryResult,但我不知道如何读它。

1 个答案:

答案 0 :(得分:0)

请参阅此示例:http://msdn.microsoft.com/en-us/library/vstudio/dd756367(v=vs.100).aspx

基本上你想要这样的东西:

// Get the original query from the result.
DataServiceQuery<Customer> query = result as DataServiceQuery<Customer>;

byte[] resultBytes = query.EndExecute(result))
// Convert the bytes to your PDF or whatever

如何进行转换取决于您;这取决于你当然是序列化了字节。

相关问题