<p>We have an encryption service that we've exposed over net. tcp. Most of the time, the service is used to encrypt/decrypt strings. However, every now and then, we the need to encrypt large documents (pdf, JPG, bmp, etc.).</p>

<p>What are the best endpoint settings for a scenario like this? Should I accept/return a stream? I've read a lot about this, but no one gives guidance on what to do when the large file doesn't occur frequently.</p>

[{'answer_id': 46311, 'author': 'Guy Starbuck', 'author_id': 2194, 'author_profile': 'https://Stackoverflow.com/users/2194', 'pm_score': 1, 'selected': False, 'text': "<p>One pattern you could follow is to have an asynchronous service that works on files on a shared file system location:</p>\n\n<ol>\n<li>Place the file to be encrypted on a shared location</li>\n<li>Call the service and tell it to encrypt the file, passing both the location and name of the file, and the addres of a callback service on the client</li>\n<li>The service would encrypt the file and place the encrypted copy in a shared location (the same as where the unencrypted was placed or different, doesn't matter)</li>\n<li>The service would call back to the client, giving the name and location of the encrypted file</li>\n<li>The client can retrieve the encrypted file</li>\n</ol>\n"}, {'answer_id': 47808, 'author': 'Jeremy McGee', 'author_id': 3546, 'author_profile': 'https://Stackoverflow.com/users/3546', 'pm_score': 3, 'selected': True, 'text': '<p>MSDN describes <a href="http://msdn.microsoft.com/en-us/library/ms789010.aspx" rel="nofollow noreferrer">how to enable streaming over WCF</a> rather well. </p>\n\n<p>Note, if the link between client and server needs to be encrypted, then you\'ll need to "roll your own" encryption mechanism. The default <code>net.tcp</code> encryption requires X.509 certificates, which won\'t work with streams as this kind of encryption needs to work on an entire message in one go rather than a stream of bytes. </p>\n\n<p>This, in turn, means that you won\'t be able to authenticate the client using the default WCF security mechanisms as authentication requires encryption. The only work-around for this that I know of is to implement your own custom behaviour extensions on client and server to handle authentication. </p>\n\n<p>A really good reference on how to add custom behaviour extensions is <a href="http://www.winterdom.com/weblog/2006/10/02/CustomWCFBehaviorsThroughAppConfig.aspx" rel="nofollow noreferrer">here</a>: this documents how to provide custom configuration, too (something that I don\'t think is discussed anywhere in the MSDN documents at this time).</p>\n'}]
['https://Stackoverflow.com/questions/46277', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/781/']