I am trying to save an image in a database through a WCF. This is my code.
public void saveImage(Stream stream, string size)
{
//int intsize = Convert.ToInt32(size);
byte[] buffer = new byte[10000];
int bytesRead, totalBytesRead = 0;
string encodedData = "";
do
{
bytesRead = stream.Read(buffer, 0, buffer.Length);
encodedData = encodedData + Convert.ToBase64String(buffer,
Base64FormattingOptions.InsertLineBreaks);
totalBytesRead += bytesRead;
} while (bytesRead > 0);
And this is the contract.
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "SaveImage/{size}")]
void saveImage(Stream stream, string size);
And finally this is part of my config file
<system.serviceModel>
<services>
<service behaviorConfiguration="RestServiceBehavior" name="ABBStreamService.ABBConnectStreamWCF">
<endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" bindingConfiguration="webHttpBinding" contract="ABBStreamService.IABBConnectStreamWCF" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="webHttpBinding" transferMode="Streamed" maxReceivedMessageSize="2147483647" maxBufferSize="10485760" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00">
<readerQuotas maxStringContentLength="2147483647" maxArrayLength="1000000" />
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="RestServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
When i try to run the service with only the Stream as parameter, it works. But when i try to add another parameter it fails.