Web服务无法从Android客户端接收字符串base64?

时间:2012-12-11 05:08:48

标签: android web-services

我在从android客户端接收字符串base64时遇到麻烦。当弦长超过80k左右。我正在使用fidder来测试webservice。

这是我的webconfig:

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

和我的方法(只是为了测试收到的webservice)

[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;
        }

0 个答案:

没有答案