Custom MTOM binding and Max upload size - wcf

I'm using the binding configuration below for my upload service,
<binding name="FileUploadSTSBinding">
<security authenticationMode="UserNameOverTransport"
requireDerivedKeys="false"
keyEntropyMode="ServerEntropy"
requireSecurityContextCancellation="false"
requireSignatureConfirmation="false">
</security>
<mtomMessageEncoding/>
<httpsTransport
transferMode="Streamed"
maxReceivedMessageSize="2147483647"/>
</binding>
But with this setting, I'm not able to upload big files like more than 1mb, server response is bad request.
Any thoughts?

You need to set the maxRequestLength attribute as well for the upload to work. It can here found in the web.config file here:
<configuration>
<system.web>
<httpRuntime>
Check that the IIS app pool identity has the right to write to the temp folder to be able to temporarily store the incoming data.

Related

WCF Unable to upload large image files

I have created a WCF REST in .net and I am unable to upload large files on server. When I test the things it will show me error on PostMan Client.
413 Request Too Large
I have changed the web settings. to this.
<webHttpBinding>
<binding name="webHttpBinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Streamed">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
</security>
</binding>
</webHttpBinding>
This is me request stream.
Unable to paste my request stream.
A couple of things to check.
First, did you assign the "webHttpBinding" to an explicit endpoint? Something like this, in the <system.serviceModel> section:
<services>
<service name="YourServiceName">
<endpoint address="" binding="webHttpBinding"
bindingConfiguration="webHttpBinding"
contract="FullyQualified.IContractName" />
</service>
</services>
Unless you assign the configuration "webHttpBinding" to an endpoint via the bindingConfiguration attribute, the default (smaller) values for webHttpBinding will be used.
Alternatively, you could make the configuration you specified the default for webHttpBinding by omitting the name attribute in the <binding> element.
Another thing to check is the maxRequestLength value in the <httpRuntime> element in your config file. You can specify a maximum value of 2147483647 (Int32.MaxValue, basically) in the <system.web> section of your config file, like this:
<system.web>
<httpRuntime maxRequestLength="2147483647" />
</system.web>

reliableSession enabled="true" in Service or client sie?

I have created service which uses nettcpip binding.I want check session id of client and server.According to my knowledge by default reliable sessions are not enabled.That's why I am getting different value.I want to enable reliable sessions so I can I same session id for client and server.In which config file I have to do that setting service or client?
<bindings>
<netTcpBinding>
<binding name="netTCP">
<reliableSession enabled="true"/>
</binding>
</netTcpBinding>
</bindings>

Remote server returned an unexpected response. (413) Requested entity too large

When I upload a photo from my WP7 to my WCF web service I get '413 Request Entity Too Large', and no matter what I do, I cannot stop it from happening.
My binding information for the web service is:
<bindings>
<basicHttpBinding>
<binding name="uploadfilebinding" closeTimeout="10:01:00"
maxBufferSize="2147483646" maxBufferPoolSize="2147483646"
maxReceivedMessageSize="2147483646" openTimeout="10:01:00"
receiveTimeout="10:10:00" sendTimeout="10:01:00"
messageEncoding="Mtom" transferMode="StreamedRequest">
<readerQuotas maxDepth="2147483646" maxStringContentLength="2147483646"
maxArrayLength="2147483646" maxBytesPerRead="2147483646"
maxNameTableCharCount="2147483646" />
</binding>
</basicHttpBinding>
</bindings>
As you can see I have set maxReceivedMessageSize to the highest I can, but to no avail, Can anyone help me please?
My server is 'Windows Server 2008 R2 Standard' and the service is running under .NET 4.
Thanks in advance,
Lee
P.S. If you need anymore information, please ask and I'll post it.
Thanks for the replies:
As this is a WP7 app, the client configuration file is a hidden file called 'ServiceReferences.ClientConfig' that is created by the service, and the binding in there is now:
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IMbcSync" closeTimeout="10:01:00"
maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" openTimeout="10:01:00"
receiveTimeout="10:10:00" sendTimeout="10:01:00"
transferMode="StreamedResponse">
</binding>
</basicHttpBinding>
</bindings>
But I'm still getting the same error. Any more suggestions would be much appreciated?
Lee
There are multiple places that you may increase to the maximum possible size. Some of them are WCF related and some of them are IIS related. In addition to the options mentioned in the comments, try to increase the followings (maxRequestLength, and maxAllowedContentLength) in your config file on the server side to take care of the IIS side too:
<system.web>
<httpRuntime maxRequestLength="2147483647" useFullyQualifiedRedirectUrl="true" executionTimeout="14400"/>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<security>
<requestFiltering allowDoubleEscaping="true">
<requestLimits maxAllowedContentLength="2147483647"/>
<fileExtensions allowUnlisted="true"/>
<verbs allowUnlisted="true"/>
</requestFiltering>
</security>
</system.webServer>

WCF Streaming not working at server

I have used WCF service to transfer large files in chunks to the server
for that i have reference this article http://kjellsj.blogspot.com/2007/02/wcf-streaming-upload-files-over-http.html
I have configured my application on IIS on my machine. Its work fine here. It allows upto 64mb file upload. But when we have published the site. It allows only maximum 30Mb file if i try to upload more than that i got error 404 - resource not found.
Here is the binding config i have used.
<basicHttpBinding>
<!-- buffer: 64KB; max size: 64MB -->
<binding name="FileTransferServicesBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" transferMode="Streamed" messageEncoding="Mtom" maxBufferSize="65536" maxReceivedMessageSize="67108864">
<security mode="None">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
Please suggest to me if I am missing anything and if required more code please let me know
On your webserver did you adjust the maximum upload size?
Goto "Request Filtering" for the target app, Open the feature, on the right side choose "Edit Feature Settings", in the dialog select a size larger than 30000000 (the default).
If on your local box you were hosting in Cassini, or your local box had different limits this might occur.

Silverlight - WCF Enable Binary Encoding

I have a WCF service that is returning a lot of data. I want to compress that information so I thought that using BinaryEncoding would be appropriate.
Currently, I have a binding setup in my web.config as follows:
<binding name="myCustomBinding" closeTimeout="00:05:00" openTimeout="00:05:00"
receiveTimeout="00:05:00" sendTimeout="00:05:00">
<binaryMessageEncoding />
<httpTransport maxReceivedMessageSize="8388608" maxBufferSize="8388608">
<extendedProtectionPolicy policyEnforcement="Never" />
</httpTransport>
</binding>
In my ServiceReferences.clientconfig file, I have the following binding settings:
<binding name="CustomBinding_MyService">
<httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
<extendedProtectionPolicy policyEnforcement="Never" />
</httpTransport>
</binding>
Oddly, this configuration will not work. As soon as I remove the <binaryMessageEncoding /> line from the web.config, everything works fine.
My question is, how do I use binary message encoding? Is there something I need to configure in my ServiceReferences.clientconfig?
Thank you
Can you define "will not work"?
Note that the client and server must agree; Silverlight has only a limited subset of extension points, but it seems that <binaryMessageEncoding/> is supported (source and more info) - so perhaps add it to the client?