tags:

views:

702

answers:

2

Configuration details are as follows:

Web.config of Wcf service which is hosted.

<basicHttpBinding>
    <binding name="HttpBinding_MTOM" messageEncoding="Mtom" 
             transferMode="Streamed" maxBufferSize="65536" 
             maxReceivedMessageSize="534773760">
      <security mode="None">
        <transport clientCredentialType="None" />
      </security>
    </binding>
</basicHttpBinding>
<services>
   <service name="OA.Smart.Services.FileTransferService"
            behaviorConfiguration="FileTransferServiceBehavior">
      <endpoint address="" 
                binding="basicHttpBinding" 
                bindingConfiguration="HttpBinding_MTOM"
                contract="OA.Smart.ServiceContract.IFileTransferService">
         <identity>
            <dns value="localhost" />
         </identity>
      </endpoint>
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
   </service>      
</services>
<behavior name="FileTransferServiceBehavior">
   <serviceMetadata httpGetEnabled="true" />
   <serviceDebug includeExceptionDetailInFaults="false" />
</behavior>

I have a smart client application which accesses this WCF service.App.Config is as follows

<bindings>
  <basicHttpBinding>
 <binding name="BasicHttpBinding_IFileTransferService" 
              closeTimeout="00:30:00" openTimeout="00:30: 
              receiveTimeout="00:30:00" sendTimeout="00:30:00"
   allowCookies="false" bypassProxyOnLocal="false" 
              hostNameComparisonMode="StrongWildcard"
   maxBufferSize="65536" maxBufferPoolSize="524288" 
              maxReceivedMessageSize="65536"
   messageEncoding="Mtom" textEncoding="utf-8" 
              transferMode="Streamed" useDefaultWebProxy="true">
     <readerQuotas 
              maxDepth="32" maxStringContentLength="8192" 
              maxArrayLength="16384" maxBytesPerRead="4096" 
              maxNameTableCharCount="16384" />
         <security mode="None">
             <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="" />
             <message clientCredentialType="UserName" algorithmSuite="Default" />
         </security>
      </binding>
   </basicHttpBinding>
</bindings>
<client>
    <endpoint 
       address="http://localhost:4149/OA.Smart.ServiceHost/FileTransferService.svc"
       behaviorConfiguration="defaultServiceBehaviour"
       binding="basicHttpBinding"  
       bindingConfiguration="BasicHttpBinding_IFileTransferService"
       contract="FileTransferServiceReference.IFileTransferService"
       name="BasicHttpBinding_IFileTransferService">
    </endpoint>
</client>
<behaviors>
   <endpointBehaviors>
       <behavior name="defaultServiceBehaviour">
           <dataContractSerializer maxItemsInObjectGraph="2147483646" />
       </behavior>
   </endpointBehaviors>
</behaviors>

With this configuration in place whenever i try to upload my file,It throws as error

System.Net.WebException: The remote server returned an error: (400) Bad Request.
   at System.Net.HttpWebRequest.GetResponse() 
   at System.ServiceModel.Channels.HttpChannelFactory.
        HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)}

However if i change transferMode="Streamed" to "Buffered" it works as expected. I do not understand why it behaves this way. TransferMode of WCF service is streamed, so it should work with streamed.

Please tell me how to make it work with transferMode="Streamed"

A: 

You only want to upload files to the server? In that case, have you tried using

transferMode="StreamedRequest"

instead of "Streamed" ?? Any difference?

Also, can you show us the service contract (the interface you're programming against) ?? That might also gives us a clue.

Marc

marc_s
+1  A: 

Problem was with hosting WCF services.I had hosted them on Cassini(Web server which ships with VS2008) instead of IIS.Cassini does not allow streaming over HTTP.So just using IIS to host WCF services resolved this issue.

Rohit