none
Error while sending and receiving byte array in WCF service RRS feed

  • Question

  • hello,

    I want to send an image in form of byte array to wcf service. I am getting error while doing so

    "The remote server returned an unexpected response: (400) Bad Request. "

    I modified my client bindings and service config bindings to accept large data. but I am still getting the error. I pasted my client and server configurations

    client config:

    ----------------------

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

     

     

     

     


    ------\
    service config:

    <bindings>
          <basicHttpBinding>
            <binding name="BasicHttpBinding_IService1"  closeTimeout="00:01:00"
              openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
              allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
              maxBufferSize="67108864" maxBufferPoolSize="67108864" maxReceivedMessageSize="67108864"
              textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true" messageEncoding="Text">
              <readerQuotas maxDepth="32" maxStringContentLength="67108864" maxArrayLength="67108864"
                  maxBytesPerRead="67108864" maxNameTableCharCount="16384" />
              <security mode="None">
                <transport clientCredentialType="None" proxyCredentialType="None"
                    realm="" />
                <message clientCredentialType="UserName" algorithmSuite="Default" />
              </security>
            </binding>
          </basicHttpBinding>
        </bindings>
         
        <services>
          <service name="IScoreService.IService1">
              <endpoint address="" binding="basicHttpBinding" contract="IScoreService.IService1" bindingConfiguration="BasicHttpBinding_IService1" ></endpoint>
              <endpoint address="" binding="mexHttpBinding" contract="IMetadataExchange"/>
          </service>   
        </services>
       
        <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="true"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
       
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

    -----
    service code


     bool IService1.GetByteArray(byte[] barray)
            {
                bool recievedArray = false;

                if (barray.Length > 0)
                {
                    recievedArray = true;
                }

                return recievedArray;
            }


    --
    client code:

     ServiceReference1.Service1Client client1 = new ServiceReference1.Service1Client();
                    label2.Text = client1.GetData(10);

                    //FileStream instream1 = File.OpenRead(filePath);
                    byte[] slapimage = Utilities.returnByteArray(filePath);

     

                    bool isarray = client1.GetByteArray(slapimage);

                    if(isarray)
                    {
                        label2.Text = "Byte Array received";
                    }

    please do see if you can assist me with this or if there is any other way to send image to wcf service and receive it as well.

     

    Friday, April 26, 2013 1:52 PM

Answers

  • Hi,

    First of all, please check if you have apply the "BasicHttpBinding_IService1" to the endpoint at your client config.

    Also check this thread to get which configuration settings need to be checked when transfer large amount of data in operations.

    #how to set increase WCF response size ?

    http://forums.asp.net/t/1795600.aspx/1

    If the issue still exists, I would suggest you enable tracing for your service to help to locate the issue.

    #Configuring Tracing

    http://msdn.microsoft.com/en-us/library/ms733025.aspx

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, April 29, 2013 10:08 AM
    Moderator
  • Hi,

    thanks for reply. I got this error when i was using managed host for hosting the service(WCF Service Application). This Application is using IIS for hosting and did not consider the endpoint of my console application. 

    After that, i created WCF Service Library which then worked fine later as it is using the inbuilt servicehost and WCFTestClient and it considers the endpoint and binding that is specified in the config. 


    deepak

    Friday, May 3, 2013 5:51 PM

All replies

  • Hi,

    First of all, please check if you have apply the "BasicHttpBinding_IService1" to the endpoint at your client config.

    Also check this thread to get which configuration settings need to be checked when transfer large amount of data in operations.

    #how to set increase WCF response size ?

    http://forums.asp.net/t/1795600.aspx/1

    If the issue still exists, I would suggest you enable tracing for your service to help to locate the issue.

    #Configuring Tracing

    http://msdn.microsoft.com/en-us/library/ms733025.aspx

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, April 29, 2013 10:08 AM
    Moderator
  • Hello..

    Is your code working for small sized byte array??

    However,

    Set below settings in both config files and verify.

    messageEncoding="Mtom" transferMode="Streamed"

    Thanks.


    Happy Coding, Kishore.

    Monday, April 29, 2013 11:51 AM
  • Hello..

    Is your code working for small sized byte array??

    However,

    Set below settings in both config files and verify.

    messageEncoding="Mtom" transferMode="Streamed"

    Thanks.


    Happy Coding, Kishore.

    Additionally, you also may need to add below tag inside <system.Web> in both config files.

     <httpRuntime maxRequestLength="2147483647" executionTimeout="15000"/>

    Thanks.


    Happy Coding, Kishore.

    Monday, April 29, 2013 12:18 PM
  • Hi,

    thanks for reply. I got this error when i was using managed host for hosting the service(WCF Service Application). This Application is using IIS for hosting and did not consider the endpoint of my console application. 

    After that, i created WCF Service Library which then worked fine later as it is using the inbuilt servicehost and WCFTestClient and it considers the endpoint and binding that is specified in the config. 


    deepak

    Friday, May 3, 2013 5:51 PM