none
Any way to support Streaming in wshttpBinding in WCf 3.5 RRS feed

  • Question

  • I have a WCF service. I am not able to read buffer data. I have done thing in basichttpbinding but not file movement from client to server in wshttpbinding

    My Application code/contract and config

    [ServiceContract]    
    public interface IBatchManagementService
    {     
    
        [OperationContract]
        void UploadManufacturerCSV(FileUploadMessage msg);      
    }    
    
    [MessageContract]
    public class FileUploadMessage
    {
        [MessageHeader(MustUnderstand=true)]
        public string FileName { get; set; }
    
        [MessageHeader(MustUnderstand = true)]
        public string BatchId { get; set; }
    
        [MessageBodyMember(Order = 1)]
        public Stream FileByteStream { get; set; }
    }
    
    On Server side i am reading it as 
         public void UploadManufacturerCSV(FileUploadMessage request)
            {
            var oFileUploadResponse = new FileUploadResponse();
                strFilePath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + @"\ManufacturerCSV\" +
                              request.FileName;
                try
                {
                    using (var sourceStream = request.FileByteStream)
                    {
                        FileStream targetStream = null;
                        using (targetStream = new FileStream(strFilePath, FileMode.Create, FileAccess.Write, FileShare.None))
                        {
                            const int bufferLen = 2048;
                            var buffer = new byte[bufferLen];
                            int count = 0;
                            while ((count = sourceStream.Read(buffer, 0, bufferLen)) > 0)
                            {
                                targetStream.Write(buffer, 0, count);
                            }
                            targetStream.Close();
                            sourceStream.Close();
                            targetStream.Dispose();
                            sourceStream.Dispose();
                        }
                    }
                    oFileUploadResponse.Success = "true";
                }
                catch (Exception ex)
                {
                    //LoggingHandler.Log(ex);
                    oFileUploadResponse.Success = "false";
                    oFileUploadResponse.Error = "An Error Occured while uploading file:" + ex.Message;
                }
    }
    
    My client config is
    
     <system.serviceModel>
        <bindings>      
          <wsHttpBinding>       
            <binding name="WSHttpBinding_IBatchManagementService" closeTimeout="00:10:00"
              openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
              bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
              maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text"
              textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false" 
                    >
              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
                maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
              <reliableSession ordered="true" inactivityTimeout="00:10:00"
                enabled="false" />
              <security mode="Message">
                <transport clientCredentialType="Windows" proxyCredentialType="None"
                  realm="" />
                <message clientCredentialType="Windows" negotiateServiceCredential="true"
                  algorithmSuite="Default" establishSecurityContext="true" />
              </security>
            </binding>
          </wsHttpBinding>
        </bindings>
        <client>      
          <endpoint address="http://localhost/myconfig/Test.svc"
            binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IBatchManagementService"
            contract="BTWABatchManagement.IBatchManagementService" name="WSHttpBinding_IBatchManagementService">
            <identity>
              <dns value="localhost" />
            </identity>
          </endpoint>
        </client>
      </system.serviceModel>
    
      My Server Config is 
      <system.web>


    Kamran Shahid Application Developer (MCP,MCAD,MCSD.NET,MCTS,MCPD.net[web])

    Thursday, August 28, 2014 3:22 AM

Answers

  • In the end I have used basichttpbinding for that service

    Kamran Shahid Application Developer (MCP,MCAD,MCSD.NET,MCTS,MCPD.net[web])

    • Marked as answer by Kamran Shahid Sunday, August 31, 2014 4:23 PM
    Sunday, August 31, 2014 4:23 PM

All replies

  • In the end I have used basichttpbinding for that service

    Kamran Shahid Application Developer (MCP,MCAD,MCSD.NET,MCTS,MCPD.net[web])

    • Marked as answer by Kamran Shahid Sunday, August 31, 2014 4:23 PM
    Sunday, August 31, 2014 4:23 PM
  • Hi,

    It's very glad to see that you finally figure the issue out by yourself and it would be grateful if you could share the solution with us, and welcome to post your question on this forum in your future programming.

    Monday, September 1, 2014 1:44 AM
  • Hi Tuesday,

    I have already mentioned that i have used basichttpBinding instead of wshttp as workaround.


    Kamran Shahid Application Developer (MCP,MCAD,MCSD.NET,MCTS,MCPD.net[web])

    Monday, September 1, 2014 2:12 PM