RAJESH
RAJESH

Reputation: 1

WCF Service Bad request when I try to send image as byte[]

Here I showed full functionality of image upload via WCF function.

Whenever I call the below service I am getting bad request. Please find where I made mistakes.

My wcf servie:

http://XXX.XXX.X.XX:/RestServiceImpl.svc/send?canvasbyte=[B@40fa5860&EmployeeID=1

My Service Interface:

    [OperationContract]
    [WebGet(
        ResponseFormat = WebMessageFormat.Json,
        BodyStyle = WebMessageBodyStyle.Wrapped,
        UriTemplate = "/send?canvasbyte={imgbyte}&EmployeeID={EmployeeID}")]
    string sendresponse(Byte[] imgbyte, string EmployeeID);

My SVC

 public string sendresponse(Byte[] imgbyte, string EmployeeID)
    {
       db.GetExcuteNonQuery("update emp_tb_eob_Employee set Signature='" + imgbyte + "'      where EmployeeID=" + EmployeeID);
        return "Success";
    }

Webconfig File

  <?xml version="1.0" encoding="UTF-8"?>
   <configuration>
    <connectionStrings>
    <add name="Databaseconnection" connectionString="Database=Test_Exenta;Server=192.168.1.XX;User ID=XXXXX;Password=XXXXX" providerName="System.Data.SqlClient" /></connectionStrings>
<system.web>
<httpRuntime maxUrlLength="2097151" maxQueryStringLength="2097151"        maxRequestLength="2097151" requestValidationMode="2.0" relaxedUrlToFileSystemMapping="true" />
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
 <services>
   <service name="RestService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour">
    <host>
      <baseAddresses>
        <add baseAddress="http://192.168.1.11:5252" />
      </baseAddresses>
    </host>
    <endpoint address="" binding="webHttpBinding" contract="RestService.IRestServiceImpl" behaviorConfiguration="web" bindingConfiguration="RESTServiceBinding">
    </endpoint>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehaviour">
      <!-- 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>
  <endpointBehaviors>
    <behavior name="web">
      <webHttp />
    </behavior>
  </endpointBehaviors>
</behaviors>
<bindings>
  <webHttpBinding>
    <binding name="RESTServiceBinding" maxReceivedMessageSize="2147483647"  maxBufferSize="2147483647"  maxBufferPoolSize="2147483647"  closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" transferMode="Streamed" sendTimeout="00:01:00">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
          maxArrayLength="2147483647" maxBytesPerRead="2147483647"
          maxNameTableCharCount="2147483647" />
      <security mode="None" />
    </binding>
  </webHttpBinding>
</bindings>
</system.serviceModel>
<system.webServer>

<modules runAllManagedModulesForAllRequests="true" />
    <directoryBrowse enabled="true" />
    <defaultDocument>
        <files>
            <remove value="Default.htm" />
            <remove value="Default.asp" />
            <remove value="index.html" />
            <remove value="index.htm" />
            <remove value="iisstart.htm" />
            <remove value="default.aspx" />
            <add value="RestServiceImpl.svc" />
        </files>
    </defaultDocument>
</system.webServer>
</configuration>

Upvotes: 0

Views: 1059

Answers (1)

Seymour
Seymour

Reputation: 7067

You may want to consider passing the image as either a base64 encoded string or a stream.

The following link outlines the options well:
How to return a Base64 encoded byte array from a WCF REST service using JSON?

Upvotes: 1

Related Questions