locked
WCF call to save Image RRS feed

  • Question

  • User1903768026 posted

    I have create a wcf service that accepts base64string and used for image

    1) when base64 string is small than it works properly and i can debug my WCF service.

    2) When length of base64 length is exceeds than it creates issue and gives belwo message and even i put the debug point on first line of WWCF service but debug not reached there,.

    The InnerException message was 'There was an error deserializing the object of type System.String. The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader.'. Please see InnerException for more details.'. See server logs for more details

    After google every thing i found some configuration issue in web.config for BIndings and Endpoint, I also modify it accordingly but no success.

    Here is code of web.config of my WCF service.

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <connectionStrings>
        <add name="eLanungeConnection" connectionString="Data Source=server-1;Initial Catalog=Dating;User ID=sa;Password=JaiksjdhY+7890" providerName="System.Data.SqlClient" />
      </connectionStrings>
      <appSettings>
    
       
      </appSettings>
      <system.web>
        <compilation debug="true" targetFramework="4.0" />
        <httpRuntime  maxRequestLength="2048576" executionTimeout="3600" requestLengthDiskThreshold="8192" />
      </system.web>
      <system.net>
        <settings>
          <httpWebRequest useUnsafeHeaderParsing="true" />
        </settings>
      </system.net>
      <system.serviceModel>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
        <bindings>
          <wsHttpBinding>
            <binding name="webHttpBinding"  maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" >
              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
         maxArrayLength="2147483647" maxBytesPerRead="2147483647"
         maxNameTableCharCount="2147483647" />
    
            </binding>
          </wsHttpBinding>
    
          <webHttpBinding>
            <binding name="WebConfiguration"
                     maxBufferSize="65536"
                     maxReceivedMessageSize="2000000000"
                     transferMode="Streamed"
                     >
    
            </binding>
    
          </webHttpBinding>
        </bindings>
        <services>
          <service behaviorConfiguration="TutorialBehavior" name="eStorageServices.Service">
            <endpoint address="" behaviorConfiguration="AjaxBehavior" binding="webHttpBinding"  bindingConfiguration="WebConfiguration"  contract="eStorageServices.IService"></endpoint>
            <!--<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>-->
          </service>
          <service behaviorConfiguration="TutorialBehavior" name="eStorageServices.PhotoAlbum">
            <endpoint address="" behaviorConfiguration="AjaxBehavior" binding="webHttpBinding" bindingConfiguration="WebConfiguration"   contract="eStorageServices.IPhotoAlbum"></endpoint>
          </service>
        </services>
        <behaviors>
          <endpointBehaviors>
            <behavior name="AjaxBehavior">
              <webHttp helpEnabled="true" />
            </behavior>
    
    
          </endpointBehaviors>
          <serviceBehaviors>
            <behavior name="TutorialBehavior">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" />
            </behavior>
            <behavior name="">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
      <system.webServer>
        <staticContent>
          <!--<mimeMap fileExtension=".mp4" mimeType="video/mp4" />
          <mimeMap fileExtension=".m4v" mimeType="video/m4v" />-->
        </staticContent>
      </system.webServer>
    </configuration>
    

    ==================================================================

    Code of the function that define in WCF service:-

     public Core.DO.IphoneResponseObject UploadPhoto(string FileName, string DeviceId, string Base64String, long UserId, long ParentId, long[] PhotoAlbumIds)

    {

    //code

    }

    =============================================================================

    ==============================================================================

    Code of the web.config from here i call this WCF service.


    <?xml version="1.0"?>
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->
    <configuration>
    	<connectionStrings>
    		<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
    	</connectionStrings>
    	<system.web>
    		<compilation debug="true" targetFramework="4.0"/>
    		<authentication mode="Forms">
    			<forms loginUrl="~/Account/Login.aspx" timeout="2880"/>
    		</authentication>
    		<membership>
    			<providers>
    				<clear/>
    				<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
    			</providers>
    		</membership>
    		<profile>
    			<providers>
    				<clear/>
    				<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
    			</providers>
    		</profile>
    		<roleManager enabled="false">
    			<providers>
    				<clear/>
    				<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/"/>
    				<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/"/>
    			</providers>
    		</roleManager>
    	</system.web>
    	<system.webServer>
    		<modules runAllManagedModulesForAllRequests="true"/>
    	</system.webServer>
     <system.serviceModel>
      <behaviors>
       <serviceBehaviors>
        <behavior name="">
         <serviceMetadata httpGetEnabled="true" />
         <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
       </serviceBehaviors>
      </behaviors>
      <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
     </system.serviceModel>
    </configuration>
    

    ==========================================================================

    Code used to call the WCF Service.

     string baseaddress = "http://122.128.0.110/MyServices/PhotoAlbum.svc/UploadPhoto";
    
    
                  Label1.Text = SendRequest(baseaddress, "POST", "application/json",
    @"{ ""UserId"": ""52"", ""DeviceId"": ""D0B7C762-C893-43B9-BEDB-4B5624"", ""FileName"": ""image1.png"", ""ParentId"": ""1949"", ""PhotoAlbumIds"": [""111"", ""111"", ""111""], ""Base64String"": ""iVBORw0KGgoAAAANSUhEUgAAAUAAAAI5CAIAAABfN3RpAAAAHGlET1QAAAACAAAAAAAAAR0AAAAoAAABHQAAARwAAdVmVO3DpQAAQABJREFUeAHsvYdXG1na7tv/zj1n3bPufN9MB9tgchIZJCGSQCAJJIEIAoQQOeecMyLnnESQyNEYA8Y2xm7nnHPC9ylqTh2O3T1jz9hj2l1a79prq2pXqbR3/ep5d6wf3tMfOge+aA7s7e190fP9uU6GvIO92bdbDx6l5BQp4tOClYmKxMzotDz/iHhRaKQ4PMpXHiGUK/1i4n/4c2UP/W/pHDjcOUAC/Hof4Mu37iRm5EckpAcrE0KiU6JS84JjUvwjYiWKmIDoBH6owjM4jAb4cJcnfXV/shygAH77/v3mzsWIuNTwuNTQ6OTw+IyIxCw/RZxvaKQgRCFSRPFk4fzQSBrgP9kNQv/dQ5wDJL0IocDv3r+fX11XxqcFKmIBcGxaARQYLrQkPFasiPUKCvdVxLr5h9AAH+LypC/tT5YDFMCoA0OBB8a04THJwcp4WWSiIiFTHp8BBRaHx4jCYC""}");
    




    ============================================================================================================

    ================

      public string SendRequest(string uri, string method, string contentType, string body)
        {
            string responseBody = null;

            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(uri);
            
            req.Method = method;
            req.Timeout = 90000;
            if (!String.IsNullOrEmpty(contentType))
            {
                req.ContentType = contentType;
            }
            if (body != null)
            {
                byte[] bodyBytes = Encoding.UTF8.GetBytes(body);
                req.GetRequestStream().Write(bodyBytes, 0, bodyBytes.Length);
                req.GetRequestStream().Close();
            }

            HttpWebResponse resp;
            try
            {
                resp = (HttpWebResponse)req.GetResponse();
            }
            catch (WebException e)
            {
                resp = (HttpWebResponse)e.Response;
            }
            
         
            Stream respStream = resp.GetResponseStream();
            if (respStream != null)
            {
                responseBody = new StreamReader(respStream).ReadToEnd();
                Console.WriteLine(responseBody);
            }
            else
            {
                Console.WriteLine("HttpWebResponse.GetResponseStream returned null");
            }
           
            return responseBody;

        }============================================================


    W






    Thursday, January 31, 2013 5:22 AM

All replies