0

I have made a web service to receive Base64string of image and image name from android app . I want to store this data into my sql server . but i have a problem when i pass this data to web service . here is my url : http://localhost:36690/api/Data/GetImage?base64String=/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wAARCADIAMgDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDg6K6v+zrP/n2j/Kj+zrP/AJ9o/wAqQrnKVp+Hv+QhJ/1yP8xWx/Z1n/z7R/lVHVo0srVZbVRDIXClk4JGD/h+lAXNeiuS+33n/PzJ/wB9Ufb7z/n5k/76oA66qmp/8g2f/drnPt97/wA/Mn/fRqazurie7iim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+27v+7F/3yf8AGqV5/wAf9z/11b+ZqKmM0v7bu/7sX/fJ/wAaP7bu/wC7F/3yf8azaKANy2tY9Wi+1XJYSE7fk4HHSpf7CtP70v8A30P8KXQf+Qb/AMDNaVIRmf2Faf3pf++h/hR/YVp/el/76H+FadFAGJdf8SXZ9kJPn53b+cY+mPWijxH1tf8Agf8ASigDGooopjCtPw9/yEJP+uR/mKKKAOhooopCCqup/wDIOn/3aKKAOUHQfSloopjCkPQ0UUAdt3pKKKQgpR1/GiigDj7z/j/uf+urfzNRUUUxhRRRQB0Wg/8AIN/4Ga0qKKQgooooAxfEfW1/4H/SiiigD//Z&imgName=dddd

And here is my problem enter image description here

And here is my webservice

[HttpGet]
[ActionName("GetImage")]
public string GetImage(string base64String, string imgName)
{
    try
    {

        using (PhNetworkEntities context = new PhNetworkEntities())
        {
            pic pic = new pic();
            pic.path = base64String;
            pic.picname = imgName;
            context.pics.Add(pic);
            context.SaveChanges();
            return "Success";
        }

    }
    catch (DbEntityValidationException ex)
    {
        // Retrieve the error messages as a list of strings.
        var errorMessages = ex.EntityValidationErrors
                .SelectMany(x => x.ValidationErrors)
                .Select(x => x.ErrorMessage);

        // Join the list to a single string.
        var fullErrorMessage = string.Join("; ", errorMessages);

        // Combine the original exception message with the new one.
        var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

        // Throw a new DbEntityValidationException with the improved exception message.
        throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
    }
}

I'm not sure if it is code problem or web.config , so here is my web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>

    <add name="PhNetworkEntities" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=ANDROIDDB;initial catalog=PhNetwork;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" maxQueryStringLength="2097151" maxUrlLength="2097151" maxRequestLength="2097151" />
    <authentication mode="None" />


    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
    <profile defaultProvider="DefaultProfileProvider">
      <providers>
        <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
      </providers>
    </profile>
    <membership defaultProvider="DefaultMembershipProvider">
      <providers>
        <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
      </providers>
    </membership>
    <roleManager defaultProvider="DefaultRoleProvider">
      <providers>
        <add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
      </providers>
    </roleManager>
    <sessionState mode="InProc" customProvider="DefaultSessionProvider">
      <providers>
        <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
      </providers>
    </sessionState>
  </system.web>
  <system.webServer>

    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  <security>

    <requestFiltering>
      <requestLimits maxQueryString="5000000" maxAllowedContentLength="500000000" />
    </requestFiltering>
  </security>

  </system.webServer>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" />
        <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>

</configuration>

Please advice . thank you for your time .

prime
  • 331
  • 1
  • 6
  • 17

2 Answers2

1

Looking at your error message, the web service is OK. You have an Entity Framework validation error on the pic.Path field, that probably has a length limit of 500 on it. Most likely [StringLength(500)].

using (PhNetworkEntities context = new PhNetworkEntities())
{
  pic pic = new pic();
  pic.path = base64String; // <--- This field has a length validation of 500 on it.

That said, Querystrings aren't really suitable for sending images tho, the rule of thumb is ~2000 characters in a querystring, so moving towards a [FromBody] approach may be beneficial in the long run.

To send a large string, if you alter it to:

public string GetImage([FromBody]string base64String, string imgName)

Call it as

http://localhost:36690/api/Data/GetImage?imgName=dddd

But pass the large string in the body of the request:
E.g. with JSON it would be something like:

{"base64String":"blah blah blah"}
NikolaiDante
  • 18,469
  • 14
  • 77
  • 117
  • At that point you may want to consider changing the HTTP request to a POST – Amir Jan 27 '16 at 20:30
  • The call should be POST or PUT, as it's not really GETing anything :-) – NikolaiDante Jan 27 '16 at 20:31
  • @NikolaiDante what is MyImage refere to in the url ?. i return success ,I am not sure but it is working with strings with length less than 500 . – prime Jan 27 '16 at 20:35
  • @prime i just aircoded it. The example you posted had imgname=dddd, so ill update mine to match that – NikolaiDante Jan 27 '16 at 20:38
  • @NikolaiDante here is my jquery function please explain . var url = "http://localhost:36690/api/Data/GetImage"; var data = { base64String: longstring, imgName: "testAPP" }; $.ajax({ url: url, Type: 'Get', data: data, dataType: 'json', success: function (data) { alert("Success"); if (JSON.stringify(data) == "Success") { alert("Success"); } else { alert("Your attach is too large please resize your attatch and try again!"); } }, error: function (data) { alert("error!"); } }); – prime Jan 27 '16 at 20:50
  • You don't have a JQuery problem, in the webservice the object `pic` has a size restriction on the `path` property. – NikolaiDante Jan 27 '16 at 20:54
  • yes, if i use public string GetImage([FromBody]string base64String, string imgName) , what should i change in my jquery and url ? @NikolaiDante – prime Jan 27 '16 at 20:58
  • It won't fix the problem in your Entity Framework code, no matter how we get the string there you won't be able to save it into the DB. I'll reorder my answer to make it clear what the actual fix is. – NikolaiDante Jan 27 '16 at 20:59
  • ok you have clear your answer but when i have replaced my code to public string GetImage([FromBody]string base64String, string imgName) .but when I have tested it on advanced rest client App with url "http://localhost:36690/api/Data/GetImage?imgName=dddd" It is not working @NikolaiDante – prime Jan 27 '16 at 21:11
  • Did you fix the validation on the `pic` object in the C# code? – NikolaiDante Jan 27 '16 at 21:12
  • No i didn't . how can i ? @NikolaiDante – prime Jan 27 '16 at 21:19
  • public partial class pic { public int id { get; set; } public string picname { get; set; } public string path { get; set; } } @NikolaiDante – prime Jan 27 '16 at 21:30
  • And there are no annotations on it? Do you have a [mvce](http://stackoverflow.com/help/mcve) you can share? I'm at the point where I am blind. – NikolaiDante Jan 27 '16 at 21:38
  • @Mate EF isn't my strong suit, but wouldn't the annotation be on the path property, even if it is partial to something else? – NikolaiDante Jan 27 '16 at 21:48
  • Maybe... you can set .HasMaxLength(500) on modelbuilder or something. Even more, you can search across all solution "500" ... maybe It's auto-generated code . In that case, you should change the design of the table in the database [ The magic doesn't always work ] – Mate Jan 27 '16 at 22:10
0

Modify "GetImage" and try calling your web service sending a string with a len < 500

Then you can see that the problem it's a EF problem and it is not a Web service problem.

[ActionName("GetImage")]
public string GetImage(string base64String, string imgName)
{
    try
    {

        using (PhNetworkEntities context = new PhNetworkEntities())
        {
            pic pic = new pic();
            pic.path = new string('*', 502); // MODIFY!! Always FAILS!!!
            pic.picname = imgName;
            context.pics.Add(pic);
            context.SaveChanges();
            return "Success";
        }

    }
    catch (DbEntityValidationException ex)
    {
       // same as Question...
    }
}

Maybe it's auto-generated code. Check the design of the table "pics" in the database, prop of column path NVarchar(500) or Varchar(500) ?

Or maybe search in "PhNetworkEntities" where the Max Length is assigned to pic.path

Mate
  • 4,976
  • 2
  • 32
  • 38