tags:

views:

25

answers:

2

Hi i finally created a small upload wcf service. I can transfer small images on my computer, but i tried transferring a mp3 song to have some larger data. It failede with a "400 bad request" exception. I have no clue as to what is going on. I am streaming the data and found alot of resources on the net, but none seem to work, this is what i have as the services web.config:

 <?xml version="1.0"?>
<configuration>

  <system.web>
    <httpRuntime maxRequestLength="67108864"/>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" transferMode="Streamed" messageEncoding="Mtom" maxBufferSize="65536" maxReceivedMessageSize="67108864">
          <readerQuotas maxDepth="2000000" maxStringContentLength="2000000" maxArrayLength="2000000" maxBytesPerRead="2000000" maxNameTableCharCount="2000000" />
        </binding>
        <!--<binding name="ExampleBinding" transferMode="Streamed" messageEncoding="Mtom" />-->
      </basicHttpBinding>

    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

And this is my clients app.config.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IMediaServer" closeTimeout="00:10:00"
                    openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed"
                    useDefaultWebProxy="true">
                  <readerQuotas maxDepth="2000000" maxStringContentLength="2000000" maxArrayLength="2000000" maxBytesPerRead="2000000" maxNameTableCharCount="2000000" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:49689/MediaServer.svc" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IMediaServer" contract="mediaServer.IMediaServer"
                name="BasicHttpBinding_IMediaServer" />
        </client>
    </system.serviceModel>
</configuration>

As far as i can see i should be able to receive at least 64Mb of data, and the data i try to transfer is around 4Mb. Can anyone point me in the right direction as to what the error is in my configuration (at least i suspect that the error is in my configuration)

EDIT These are my contracts:

[ServiceContract]
    public interface IMediaServer
    {

        [OperationContract]
        void UploadData(UploadFile data);
    }

[MessageContract]
    public class UploadFile
    {
        public UploadFile() { }

        [MessageHeader]
        public string FileName { get; set; }

        [MessageHeader]
        public string Type { get; set; }

        [MessageHeader]
        public string AccountName { get; set; }

        [MessageBodyMember]
        public Stream data { get; set; }
    }
A: 

Your client is not configured to use Streaming. Change transfer mode in client configuration to Streamed. Also in your service configuration try to delete binding name. At the moment you are using default endpoint endpoint which uses default binding configuration = configuration without name.

Ladislav Mrnka
I made the changes, still no luck (changed in the original post), my exception is now: Message: The remote server returned an error: (400) Bad Request.Stacktrace: at System.Net.HttpWebRequest.GetResponse() at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
H4mm3rHead
And does it work with small file?
Ladislav Mrnka
No...not any longer... but if i change the client back to buffered, it works... What am i missing, seems to me its only transfers images it can fit in the buffer
H4mm3rHead
with a new stacktrace: Server stack trace: at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException, ChannelBinding channelBinding) at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
H4mm3rHead
Can you also show your service contract / data contracts / message contracts? Also set up Text message encoding on the service.
Ladislav Mrnka
Please see my edit...
H4mm3rHead
Changed the content to "Text", still no luck with "Streamed" mode, only "Buffered" mode seem to work on the client
H4mm3rHead
Bloody hell..... just migrated to IIS from the build in webserver, everything works fine now :-)
H4mm3rHead
:) avoid using development server for WCF services. Only limited feature set is supported there.
Ladislav Mrnka
A: 

Hi,

You don't necessarily go for streaming...

This errors occur due to the limits in the maximum amount of data that can be transferred through a service. These maximum limit can be altered as per the requirement by using the binding configuration. U have to alter the existing configuration. Note that the values specified here is the values which define the configuration. These values are in bytes. Which means 512000 means 500KB. So, use a value here according to the maximum memory a mp3 can take. If a song can be of 5 Mb then the value should be 5242880. If a song can take 10 Mb then 10485760. The maxReceivedMessageSize is the property which defines this.You also have to increase the maxArrayLength accordingly to hold the values as bytes. The maxArrayLength specifies the maximum length an array can extend up to i.e) a[maxArrayLength]

In server side add,

<endpoint address="" binding="basicHttpBinding" bindingConfiguration="MaxMessage" contract="Service.IService1">

and

<bindings>
  <basicHttpBinding>
    <binding name="MaxMessage" maxReceivedMessageSize="512000" maxBufferSize="512000">
      <readerQuotas maxArrayLength="512000"/>
    </binding>
  </basicHttpBinding>      
</bindings>

In Client Side add,

<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IService1" closeTimeout="00:01:00"
     openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:11:00"
     allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
     maxBufferSize="512000" maxBufferPoolSize="512000" maxReceivedMessageSize="512000"
     messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
     useDefaultWebProxy="true">
      <readerQuotas maxDepth="320" maxStringContentLength="512000"
       maxArrayLength="512000" maxBytesPerRead="40960" maxNameTableCharCount="512000" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
         realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
Siva