More on attachments

Since my monologue on the IWSDAttachment object last week, it’s occured to me that there’s a much simpler way to explain which programming patterns you have to use when reading from or writing to WSDAPI attachments.

Here’s a table that describes it.  To use this table, you need to determine whether you’re writing a client application or a service application, and you need to determine whether you’re writing to an attachment, or reading from it.  Then, look up the appropriate row in the table below, and you’ll know which programming patterns you can use.  The patterns are described below.

  • The basic pattern means you can read your attachment from the same thread as where your messaging occurs.  This only works if you’re inside a service method; you can read attachments without another thread.

  • The thread pattern is where you spin off another thread to read or write your attachment.  I described this in option 2 of the “How do I fix this?” section of the original attachment article.

  • The async pattern is where you call asynchronous versions of the proxy method in question (e.g., BeginGetWebcamImage()).  I described this in option 1 of the aforementioned section and article.  You’ll note that the async pattern isn’t available if you’re writing a service, since WSDAPI doesn’t have a notion of async service calls.

* Important note: the async pattern in the client: read scenario requires that you follow the 7-step instructions at the very end of the original attachment article, or else you risk crashing your application.

And for those of you wondering how I picked the ordering of the rows: it’s the order in which a request/response pattern is seen by the client and service in a typical operation.

Comments (3)

  1. Daniel Chen says:

    Thanks for update Dan, the table you listed is very useful. We are just planning to implement a prototype, which the service can send back binary data to client using IWSDAttachment. According to your table, we have to separate the write and send operation in two threads, and the client must read data via async version proxy interface. Is it right?

  2. dandris says:


    The table is more about the "No" items than it is about the "Yes" items.  So, the table doesn’t tell you the correct solution–but it does tell you which solutions are incorrect.

    In this case, you have to use the Async Pattern, because it is the only pattern suitable for reading from inbound response attachments in a client.  You MAY spin another thread for sending the request attachment, but it is unnecessary and will probably only complicate your solution.

    The directions at the bottom of my first attachment post clearly lead you through this process.