locked
Error while communication with WCF RRS feed

  • Question

  •  

    Hi,

    We have a silverlight application and it is communicating with WCF to retireve data. Proxy file is generated for WCF service and added .cs file to silverlight project instead of adding service reference.   one of the WCF OperatationContracts method is returning memory stream as the output.  We are receiving the following error message while calling this method from silverlight.

    The type 'System.IO.Stream' cannot be deserialized because it does not have a public parameterless constructor. Alternatively, you can make it internal, and use the InternalsVisibleToAttribute attribute on your assembly in order to enable serialization of internal members - see documentation for more details. Be aware that doing so has certain security implications.

    Please help

    Thursday, April 22, 2010 4:51 AM

Answers

  • The Stream programming model, in which WCF understands the Stream type as a special case and accepts any of its (concrete) subclasses, is not available in Silverlight. You can, in Silverlight, use the equivalent type to Stream, byte[], if you want to share the same .cs file between client and service:

    [

     

     

    ServiceContract]
    public interface ITest
    {
    #if !SILVERLIGHT
        [
    OperationContract]
        Stream GetStream(string text);
    #else
        [OperationContract(AsyncPattern = true)]
        IAsyncResult BeginGetStream(string text, AsyncCallback callback, object state);
        byte[] EndGetStream(IAsyncResult asyncResult);
    #endif
    }
    • Proposed as answer by Carlos Figueira Monday, April 26, 2010 9:51 PM
    • Marked as answer by Mog Liang Thursday, April 29, 2010 10:33 AM
    Thursday, April 22, 2010 5:22 AM