0

I have a WCF service, using NetTcpBinding TransferMode.Streamed, I'm looking to stream back to client using its callback, but i get this exception on the line host.Open:

Contract requires Duplex, but Binding 'NetTcpBinding' doesn't support it or isn't configured properly to support it.

 ServiceHost host;
    public Form1()
    {
        InitializeComponent();
    }   
    private void button1_Click(object sender, EventArgs e)
    {
        Uri baseAddress = new Uri(string.Format("net.tcp://{0}:1991/service", Dns.GetHostName()));
        host = new ServiceHost(typeof(WCF_Server.MainService), baseAddress);
        host.Open();
    }

service interface :

[ServiceContract(CallbackContract = typeof(IScreenCallback))]
public interface IScreenShot
{
    [OperationContract]
    Stream GetStream(int formatIndex);

    [OperationContract]
    void ShowGallery();
    [OperationContract]
    void CloseGallery();

    [OperationContract]
    void AddImage(Stream stream);
}

public interface IScreenCallback
{
    [OperationContract]
    void NextImage();

    [OperationContract]
    void PrevImage();

    [OperationContract]
    void AddImageClient(Stream stream);
}

how would i pass stream to client callback?

Murhaf Sousli
  • 12,622
  • 20
  • 119
  • 185

1 Answers1

1

Your IScreenShot contract isn't fully one-way. It needs to be for a duplex contract with is one-way in one direction and also one-way into the other.

That said, streaming and duplex don't mix, at all, because of internal mechanics that require the messages to be buffered. So this wouldn'[t work anyways.

To make this scenario work in a duplex mode you should chop up the data into reasonably sized byte[] chunks and transfer them in chunks instead of as streams. You can make that contract look pretty much like Stream's Write or even wrap an instance of the contract in a Stream-derived proxy-wrapper on the send side, so that it looks pretty much the same to whoever populates the stream.

Clemens Vasters
  • 2,666
  • 16
  • 28
  • maybe i don't need to use "oneway = true", i was success to stream from client to server, i just want to be able to stream back to client, i don't want to use buffered data because im streamming images. – Murhaf Sousli May 16 '12 at 20:45
  • I assume you succeeded before you added the callback contract. The callback contract changes the story. Once you do this, the shape of the main contract needs to be one-way as well. See http://msdn.microsoft.com/en-us/library/ms731064.aspx and http://msdn.microsoft.com/en-us/library/system.servicemodel.servicecontractattribute.callbackcontract.aspx for background. – Clemens Vasters May 16 '12 at 21:01
  • is there anyway to pass stream to callback client in stream mode? – Murhaf Sousli May 17 '12 at 01:40
  • I don't see the implication of using byte[] to send images back to the client instead of Streams? I'm currently using the former (byte[]) for doing this as part of a video chat i'm making in Silverlight (duplex, using netTcp) and it's working like a charm. – Mohammad Sepahvand May 17 '12 at 05:46