从WCF服务回报pdf文件? [英] Return pdf file from WCF service?

查看:99
本文介绍了从WCF服务回报pdf文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WCF服务,我想它的服务方法之一来访问一个PDF文件,并​​将其转换成流或一些其他的东西,流回到我的web应用程序,在那里我将转换的流回PDF文件。

I have a WCF service and I want to one of its service methods to access a pdf file and convert it to a stream or some other thing and return the stream to my web application, where I will be converting that stream back to a pdf file.

哪个是更好的方式,将PDF转换成字节[] 数组?

Which is the better way, converting the pdf into Stream or byte[] array?

这是我的方法

 public byte[] GetPdf(string Address)
 {
    byte[] bytes = System.IO.File.ReadAllBytes(Address);
    return bytes
 }

现在在我的web应用程序从中我打电话这个WCF服务,我想用这些字节,并将其转换回PDF格式。这是正确的方式我不知道是否返回文件流是正确的或返回为字节[]是正确的。

Now in my web application from which I am calling this WCF service, I want to use these bytes and convert them back to pdf. Is this the correct way as I'm not sure whether returning the file as stream is correct or returning as byte[] is correct

但是,当我运行的服务为宗旨的测试,我得到一个错误

But when I'm running the service for testing purpose I'm getting an error

传入消息(65536)的最大邮件大小已超出配额。为了增加配额,使用MaxReceivedMessageSize属性相应绑定元素上。

The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

我怎样才能解决这个问题,我还没有添加任何绑定或任何东西,一切都将默认为我是新来的WCF

How can I resolve this issue, I have not added any bindings or anything, everything is default as I'm new to WCF

推荐答案

美好的一天!

从书<报价href=\"http://books.google.ru/books?id=PvNrurEhmiEC&pg=PA617&dq=wcf&hl=ru&sa=X&ei=ljVoUs2kEYb-4QTBoIGgBw&redir_esc=y#v=onepage&q=wcf&f=false\"相对=nofollow>编程WCF服务作者Juval洛伊:

Quote from the book "Programming WCF Services" author Juval Lowy:

在默认情况下,当客户端和服务交换消息,
  这些消息被缓冲在接收端和递送
  仅当整个消息已被接收。这是真的
  无论是在客户端将消息发送到该服务或
  服务返回的消息给客户端。其结果是,当
  客户端调用服务,该服务后,才会调用
  客户端的消息已被全部接收;同样地,在
  客户端是畅通只用一次的结果返回的消息
  调用已在其全部被接收。对于足够
  小消息,这种交换的模式提供了一个简单的编程
  明的模型,因为造成的接收消息的等待时间是
  与消息本身的处理通常相比可以忽略不计。
  然而,当涉及到更大的消息,如涉及的人
  多媒体内容,大文件或数据 - 阻塞,直到批次
  整个消息已被接收可能是不切实际的。处理
  这样的情况下,WCF使得接收侧(无论是客户机或
  服务)开始,而消息的消息中处理数据
  仍在由信道接收的。这种类型的处理是
  称为流传输模式。对于大型有效载荷,流
  提供改进的吞吐率和响应能力,因为无论是
  接收也不当邮件被发送方受阻
  发送或接收

By default, when the client and the service exchange messages, these messages are buffered on the receiving end and delivered only once the entire message has been received. This is true whether it is the client sending a message to the service or the service returning a message to the client. As a result, when the client calls the service, the service is invoked only after the client’s message has been received in its entirety; likewise, the client is unblocked only once the returned message with the results of the invocation has been received in its entirety. For sufficiently small messages, this exchange pattern provides for a simple program- ming model because the latency caused by receiving the message is usually negligible compared with the message processing itself. However, when it comes to much larger messages—such as ones involving multimedia content, large files, or batches of data— blocking until the entire message has been received may be impractical. To handle such cases, WCF enables the receiving side (be it the client or the service) to start processing the data in the message while the message is still being received by the channel. This type of processing is known as streaming transfer mode. With large payloads, streaming provides improved throughput and responsiveness because neither the receiving nor the sending side is blocked while the message is being sent or received

有关传输文件,我使用的流与异步模式recomended。

For transfer files, I'm recomended using Stream with async pattern.

 [ServiceContract(SessionMode = SessionMode.NotAllowed)]
    public interface ITerrasoftFiles
    {
        [OperationContract(AsyncPattern = true)]
        IAsyncResult BeginGetFiles(Guid ID, AsyncCallback asyncCallBack, object asyncState);

        Stream EndGetFiles(IAsyncResult res);

        [OperationContract]
        FileInfo GetFileInfo(Guid ID);
    }

和将 transferMode =StreamedResponse在Web.config中

And set transferMode="StreamedResponse" in Web.config

<bindings>
      <netTcpBinding>
        <binding name="tcpTerrasoftFiles" transferMode="StreamedResponse">
          <security mode="None" />
        </binding>
      </netTcpBinding>
</bindings>
 <services>
    <service name="TWebServices.Services.TerrasoftFiles">
      <endpoint address="" 
                  binding="netTcpBinding" bindingConfiguration="tcpTerrasoftFiles" 
                  contract="TWebServices.Services.ITerrasoftFiles" />
      <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
     </service>
 </services>

这篇关于从WCF服务回报pdf文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆