无法使用base64字符串从rest客户端调用wcf方法

时间:2014-11-27 10:05:39

标签: wcf rest-client

我正在创建一个wcf服务,我在其中收到一个base64字符串并转换为图像以存储在我的项目中。

这是我的方法:

 public Boolean UploadProfile(int UserId, string base64String, string FileExtension)
        {
            try
            {
                string fileExtension;
                byte[] bytes = Convert.FromBase64String(base64String);
                if (FileExtension == "")
                    fileExtension = ".png";
                else
                    fileExtension = FileExtension;

                String timeStamp = GetTimestamp(DateTime.Now);
                fileExtension = timeStamp + fileExtension;
                string strFileName = "~/Images/" + fileExtension;
                using (UserRegistrationBal UserregistrationBal = new UserRegistrationBal())
                {
                    using (MemoryStream stream = new MemoryStream(bytes))
                    {
                        Image image = Image.FromStream(stream);
                        image.Save(HttpContext.Current.Server.MapPath(strFileName));
                        UserregistrationBal.UploadProfile(UserId, fileExtension);
                    }
                    return true;
                }
            }
            catch (Exception ex)
            {
                ErrorLogManager.LogError(ex);
                return false;
            }
        }




public static String GetTimestamp(DateTime value)
        {
            return value.ToString("yyyyMMddHHmmssffff");
        }

我的界面:

 [ServiceContract]
    public interface Services 
    {
           [OperationContract]
        [WebInvoke(RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json, Method = "POST")]
        Boolean UploadProfile(int UserId, string base64String, string FileExtension);
}

现在,当我从我的休息客户端调用此方法时,就像这样:

enter image description here

然后我的方法不是从rest客户端调用。

我在我的方法上保留了调试器,但我没有发生任何事情

当我传递空白的base64参数时,我的方法正在调用。

任何人都可以告诉我这是什么问题吗?

1 个答案:

答案 0 :(得分:0)

我认为您的文件大小存在问题,请将maxBufferSize,maxBufferPoolSize和maxReceivedMessageSize更改为

         maxBufferSize="2147483647"
         maxBufferPoolSize="2147483647"
         maxReceivedMessageSize="2147483647"

从您的绑定然后尝试, 我认为它应该工作。 并尝试添加

 <readerQuotas  maxDepth="2147483647"
 maxStringContentLength="2147483647"
 maxArrayLength="2147483647"
 maxBytesPerRead="2147483647"
 maxNameTableCharCount="2147483647"/>

在您的绑定中。 它会将大文件上传到REST服务。