// Retrieve the stream containing the specified attachment // from the Indigo service. public Stream GetRecipeAttachment(String docKey, String attachmentKey) { Stream stream = null; try { stream = proxy.GetAttachment(docKey, attachmentKey); if (stream == null) { throw new Exception("Attachment not found"); } #if true //TODO: SeptCTP "bug" - unable to use WCF stream with BitmapImage.StreamSource else { List <byte> bytesList = new List <byte>(); int i = stream.ReadByte(); while (i != -1) { bytesList.Add((byte)i); i = stream.ReadByte(); } stream = new MemoryStream(bytesList.ToArray()); } #endif } catch (FaultException <AttachmentNotFoundFaultException> f) { DocumentServiceHelpers.HandleException(f); } catch (FaultException <string> f) { DocumentServiceHelpers.HandleException(f); } catch (FaultException f) { DocumentServiceHelpers.HandleException(f); } catch (Exception e) { DocumentServiceHelpers.HandleException(e); } return(stream); }
// Connect to the Indigo service and retrieve the list of recipes public void OnAppStartup(object sender, StartupEventArgs e) { // Set up the Indigo service to the local store. proxy = new DocumentServiceProxy(); // Initialize the recipe list DocHeader[] headers; try { headers = proxy.GetDocHeaders(""); if ((headers != null) && (headers.Length > 0)) { recipeList = new Recipes(headers); currentIndex = 0; // Add the application specific properties Properties.Add("RecipeList", recipeList); Properties.Add("CurrentRecipe", currentIndex); } else { throw new ApplicationException("No documents found"); } } catch (FaultException <NoDocumentsFoundFaultException> f) { DocumentServiceHelpers.HandleException(f); } catch (FaultException <string> f) { DocumentServiceHelpers.HandleException(f); } catch (Exception ex) { DocumentServiceHelpers.HandleException(ex); } }
// Retrieve the recipe identified by "key" // from the Indigo service public XmlDocument GetRecipe(String key) { XmlDocument recipeDoc = null; Message query = null; Message response = null; String action = "http://Microsoft.Samples.RecipeCatalog/IDocumentService/GetDoc"; try { // Create the request message using the doc key; a document will be returned in the reply Message query = Message.CreateMessage(MessageVersion.Default, action, key); response = proxy.GetDoc(query); // Process the response message XmlReader rdr = response.GetReaderAtBodyContents(); if (!rdr.EOF) { // The service returned a document if (!response.IsFault) { recipeDoc = new XmlDocument(); recipeDoc.Load(rdr); } // The service returned a fault else { DocumentServiceHelpers.ProcessMessageFault(rdr); } } // Response message came back empty else { throw new Exception("Response message is empty"); } } catch (FaultException <DocumentNotFoundFaultException> f) { DocumentServiceHelpers.HandleException(f); } catch (FaultException <string> f) { DocumentServiceHelpers.HandleException(f); } catch (FaultException f) { DocumentServiceHelpers.HandleException(f); } catch (Exception e) { DocumentServiceHelpers.HandleException(e); } finally { if (query != null) { query.Close(); } if (response != null) { response.Close(); } } return(recipeDoc); }