Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Please dont mark it as Duplicate. I have treid many times but failed.

i am getting stream content and saving my image with static name. But i am unable to sending the image file-name,extension parameters to that post URL.

my code is like below

in Web.Config
C#
<?xml version="1.0" encoding="UTF-8"?>
<system.web>
    <compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.serviceModel>
    <services>
        <service name="PracticeWcfService1.Service1" behaviorConfiguration="ServiceBehaviour">

            <endpoint name="RestClient"
                      address="RestType"
                      binding="webHttpBinding"
                      contract="PracticeWcfService1.IService1"
                      behaviorConfiguration="PracticeWcfService1.Service1ehaviour" >
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>

            <endpoint name="RestClientWithSecure"
                      address="RestTypeWithSecure"
                      binding="webHttpBinding"
                      contract="PracticeWcfService1.IService1"
                      bindingConfiguration="PracticeWcfService1.Services.ClientServicesEndpointBinding"
                      behaviorConfiguration="PracticeWcfService1.Service1ehaviour" >
                <!--bindingConfiguration used to give the security mode like HTTPS-->
                <!--behaviorConfiguration used to define type of endpointBehaviors-->
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>

            <endpoint  name="SoapClient"
                address="SoapType"
                binding="basicHttpBinding"
                contract="PracticeWcfService1.IService1">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>

            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>

            <host>
                <baseAddresses>
                    <add baseAddress="http://localhost:33333/Service1.svc" />
                </baseAddresses>
            </host>

        </service>
    </services>
    <bindings>
        <webHttpBinding>
            <binding name="PracticeWcfService1.Services.ClientServicesEndpointBinding" transferMode="Streamed" maxBufferSize="2147483647"
                     maxReceivedMessageSize="2147483647" openTimeout="00:10:00" receiveTimeout="00:20:00" sendTimeout="00:10:00">
                <security mode="Transport">
                </security>
            </binding>
        </webHttpBinding>
    </bindings>
    <behaviors>
        <endpointBehaviors>
            <behavior name="PracticeWcfService1.Service1ehaviour">
                <webHttp/> <!--helpEnabled="true" automaticFormatSelectionEnabled="true"-->
            </behavior>
        </endpointBehaviors>
        <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" httpsGetEnabled="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" />
                <serviceThrottling maxConcurrentCalls="500" maxConcurrentInstances="250"/>
            </behavior>

        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <directoryBrowse enabled="true" />
</system.webServer>


In IService1 interface:
C#
[OperationContract]
        string RecieveImage(string fileName, Stream ImageStream);


in Service1.svc.cs
C#
 [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "UploadFile/{fileName}")] 
            public string RecieveImage(string fileName, Stream ImageStream)
                using (FileStream fs = new FileStream(@"\\192.168.1.2\Common\Pratap\" + fileName + ".jpeg", FileMode.Create))
                {
                    ImageStream.CopyTo(fs);
                    ImageStream.Close();
                }
            }
            catch (Exception ex)
            {
                throw new WebFaultException<string>(ex.Message, System.Net.HttpStatusCode.BadRequest);
            }
            return "Successsfully recieved.";
}


in Service view markup:

C#
<%@ ServiceHost Language="C#" Debug="true" Service="PracticeWcfService1.Service1" CodeBehind="Service1.svc.cs" Factory="System.ServiceModel.Activation.WebServiceHostFactory"%>


Please solve my issue...

Thanks in Advance
Posted
Comments
ZurdoDev 16-Sep-13 8:40am    
What's the error?
_Satya_ 16-Sep-13 8:50am    
Error:
For request in operation RecieveImage to be a stream the operation must have a single parameter whose type is Stream.

You can use base64 string to upload an image. First convert an image to base64 string in client from where your service is used. and in service convert that base64 string to image.
 
Share this answer
 
Comments
_Satya_ 19-Sep-13 8:08am    
Here i am unable to get the parameters like imagename,extension etc... While i am passing parameters as in uritemplate it is giving run time error.
Error:
For request in operation RecieveImage to be a stream the operation must have a single parameter whose type is Stream.

but it is perfectly working if i can pass only stream as single password.
I also tried using base64 string, but only very small size image can be uploaded, how to upload large Image ???
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900