【问题标题】:Read a pdf from WCF Data Service从 WCF 数据服务读取 pdf
【发布时间】:2013-07-12 07:46:08
【问题描述】:

我添加了一个 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 但我不知道如何阅读它。

【问题讨论】:

    标签: wcf-data-services silverlight-5.0


    【解决方案1】:

    请参阅此示例: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
    

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

    【讨论】:

      猜你喜欢
      • 2011-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-05
      • 1970-01-01
      • 2013-12-08
      • 1970-01-01
      相关资源
      最近更新 更多