无法将带参数的图像上传到wcf rest service [英] Unable to upload an image with parameters to wcf rest service

查看:83
本文介绍了无法将带参数的图像上传到wcf rest service的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请勿将其标记为重复。我已经多次treid但是失败了。



我正在获取流内容并使用静态名称保存我的图像。但我无法将图像文件名,扩展名参数发送到该帖子网址。



我的代码如下所示



在Web.Config中

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

<?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>





在IService1界面中:



In IService1 interface:

[OperationContract]
        string RecieveImage(string fileName, Stream ImageStream);





在Service1.svc.cs



in Service1.svc.cs

 [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:

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





请解决我的问题...



先谢谢



Please solve my issue...

Thanks in Advance

推荐答案

您可以使用base64字符串上传图像。首先将图像转换为客户端中使用服务的base64字符串。并在服务中将base64字符串转换为图像。
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.


我也尝试使用base64字符串,但只能上传非常小的图像,如何上传大图像???
I also tried using base64 string, but only very small size image can be uploaded, how to upload large Image ???


这篇关于无法将带参数的图像上传到wcf rest service的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆