1

We recently had to upgrade our Win 8.1 store app to Win 10. Part of that change was modifying our NetTcpBindings to instead be BasicHttpBindings for file uploads since UWP does not currently support NetTcpBindings. Our issue is that when the client calls the UploadFileMethod on the proxy class, we intercept the message before it is sent to the server so we can apply headers that are used later as follows:

public async Task UploadFileAsync(RemoteFileInfo request)
{
    using (new OperationContextScope(this.InnerChannel))
    {
        string nameSpace = @"http://tempuri.org";
        OperationContext.Current.OutgoingMessageHeaders.Add(MessageHeader.CreateHeader("FileName", nameSpace, request.FileName));
        OperationContext.Current.OutgoingMessageHeaders.Add(MessageHeader.CreateHeader("Length", nameSpace,
            request.Length));

        await Channel.UploadFileAsync(request);
    }
}

This used to work fine when we were using NetTcpBinding but since we switched to BasicHttpBinding that code is now throwing an exception on the line:

await Channel.UploadFileAsync(request);

With the exception reading:

This message cannot support the operation because it has been written.

After reading up on this exception it appears that we cannot mess with the request object at all before it is sent to the server when using BasicHttpBinding. If that is the case, how can we add OutgoingMessageHeaders to the message using properties of the request itself?

Edit: The proxy class is created as follows:

var imageProxy = new RTMImageServiceProxy(globalContext.Win10UploadBinding,
                    globalContext.ImageEndpointAddress);

Where Win10UploadBinding is configured as so:

BasicHttpBinding win10BasicBinding = new BasicHttpBinding();
win10BasicBinding.Security.Mode = BasicHttpSecurityMode.None;
win10BasicBinding.TransferMode = TransferMode.Streamed;
win10BasicBinding.SendTimeout = new TimeSpan(0, 0, 2, 0);
win10BasicBinding.MaxReceivedMessageSize = 2147483647;
this.win10UploadBinding = win10BasicBinding;

and globalContext is just a static class I used to store commonly-used variables.

user2357446
  • 656
  • 6
  • 25

1 Answers1

0

Apparently it turns out that once written cannot be altered so create a copy with adjusted headers. Equivalent issue was brought up here.
Anyway, I encourage you to create custom message inspector: class deriving IClientMessageInspector, as far as client is concerned. It provides separation between method being invoced and headers being adjusted.

Community
  • 1
  • 1
Maximus
  • 3,458
  • 3
  • 16
  • 27
  • I ended up trying to just run the code without modifying the headers using the OperationContext and I got the same error. Basically I just called "await uploadFileAsync(request);" and I still got the same exception. That doesn't really make sense since nothing has been modified or changed from the call to UploadFileAsync and the method itself calling Channel.UploadFileAsync... – user2357446 Dec 14 '15 at 19:24
  • Since you make use of this.InnerChangel I presume class derives either from ClientBase or DuplexClientBase. Is proxy corrrectly created? – Maximus Dec 14 '15 at 19:26
  • I've edited my original post to show how I am setting up the proxy – user2357446 Dec 14 '15 at 19:33