3

我无法从 android 客户端接收字符串 base64。当字符串的长度超过大约 80k 时。我正在使用 fidder 来测试 web 服务。

这是我的网络配置:

<?xml version="1.0"?>

<configuration>
  <configSections>
    <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
      <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
        <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
        <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
          <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere" />
          <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />
          <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />
        </sectionGroup>
      </sectionGroup>
    </sectionGroup>
  </configSections>

  <system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="500000">
        </jsonSerialization>
      </webServices>
    </scripting>
  </system.web.extensions>
  <system.net>
    <mailSettings>
      <smtp>
        <network host="mail.test.com" port="25" userName="smtp@test.com" password="*"/>
      </smtp>
    </mailSettings>
  </system.net>
  <connectionStrings>
    <add name="VLDBConnectionString1" connectionString="Data Source=THOINX00861-PC;Initial Catalog=VLDB;Integrated Security=True"
      providerName="System.Data.SqlClient" />
    <add name="VLDBConnectionString" connectionString="Data Source=KHANH-PC;Initial Catalog=VLDB;Integrated Security=True"
      providerName="System.Data.SqlClient" />
    <add name="VLDBConnectionString3" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=VLDB;Integrated Security=True"
      providerName="System.Data.SqlClient" />

  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </modules>
  </system.webServer>
  <system.serviceModel>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="true" />
    <standardEndpoints>
      <webHttpEndpoint>
        <!-- 
            Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
            via the attributes on the <standardEndpoint> element below
        -->
        <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
      </webHttpEndpoint>
    </standardEndpoints>
    <services>
      <service name="MyService.MyService" behaviorConfiguration="MyService.MyServiceBehaviour" >
        <endpoint address="" 
                  binding="webHttpBinding" 
                  contract="MyService.IMyService"
                  behaviorConfiguration="maxRequest">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="maxRequest">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors  >
          <behavior name="MyService.MyServiceBehaviour">
            <dataContractSerializer maxItemsInObjectGraph="4194304"/>
            <serviceMetadata httpGetEnabled="true" />
            <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

和我的方法(只是为了测试是否收到了网络服务)

[WebInvoke(Method = "POST", UriTemplate = "/File", 
        RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml)]
        public bool UploadFile(Stream fileContents)
        {

            string email, itemtId, codeimg, format;
            using (StreamReader reader = new StreamReader(fileContents))
            {
                string[] separators = { "{\"", "\":\"", "\",\"", "\"}", "email", "format", "stringcodeimg", "itemid" };
                string contents = reader.ReadToEnd();
                string[] words = contents.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                email = words[0];
                format = words[1];
                codeimg = words[2];
                itemtId = words[3];
            }

            return true;
        }
4

0 回答 0