我的代码非常适合小于45 Kb的文件但是当我上传文件大文件时,我收到了错误:
远程服务器返回错误:(400)错误请求。
描述:执行当前Web请求期间发生了未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详细信息:System.Net.WebException:远程服务器返回错误:(400)错误请求。
来源错误:
Line 120: [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] Line 121: WebApplication2.ServiceReference1.uploadfileResponse WebApplication2.ServiceReference1.IService1.uploadfile(WebApplication2.ServiceReference1.RemoteFileInfo request) { Line 122: return base.Channel.uploadfile(request); Line 123: } Line 124:
源文件:
C:\Users\KHALED\documents\visual studio 2010\Projects\WcfServicefiles\WebApplication2\Service References\ServiceReference1\Reference.cs
行:122堆栈追踪:
[WebException: The remote server returned an error: (400) Bad Request.] System.Net.HttpWebRequest.GetResponse() +6115427 System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +48 [ProtocolException: The remote server returned an unexpected response: (400) Bad Request.] System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +9455983 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +345 WebApplication2.ServiceReference1.IService1.uploadfile(RemoteFileInfo request) +0 WebApplication2.ServiceReference1.Service1Client.WebApplication2.ServiceReference1.IService1.uploadfile(RemoteFileInfo request) in C:\Users\KHALED\documents\visual studio 2010\Projects\WcfServicefiles\WebApplication2\Service References\ServiceReference1\Reference.cs:122 WebApplication2._Default.Button2_Click(Object sender, EventArgs e) in C:\Users\KHALED\documents\visual studio 2010\Projects\WcfServicefiles\WebApplication2\Default.aspx.cs:38 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
这是我的服务器的webconfig代码:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime maxRequestLength="2097151"
useFullyQualifiedRedirectUrl="true"
executionTimeout="14400"
/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="SomeServiceServiceBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="6553600"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="Service1"
maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647" transferMode="Streamed">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
<security mode="None">
<transport clientCredentialType="Ntlm"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="Service1.svc.cs" >
<endpoint address="" binding="basicHttpBinding"
bindingConfiguration="Service1"
contract="IService1" >
</endpoint>
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
这是客户端的web.config
<?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>
<configSections>
</configSections>
<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"/>
<httpRuntime maxRequestLength="2097150" />
<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="SomeServiceServiceBehavior">
<dataContractSerializer maxItemsInObjectGraph="6553600"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="SomeServiceServiceBehavior">
<dataContractSerializer maxItemsInObjectGraph="6553600"/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" closeTimeout="04:01:00"
openTimeout="04:01:00" receiveTimeout="04:10:00" sendTimeout="04:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed"
useDefaultWebProxy="true">
<readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/WcfServicefiles/Service1.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
</configuration>
答案 0 :(得分:1)
服务器的下一部分web.config
<services>
<service name="Service1.svc.cs" >
<endpoint address="" binding="basicHttpBinding"
bindingConfiguration="Service1"
contract="IService1" >
</endpoint>
</service>
</services>
有一些错误的属性值。 service元素的name属性的值必须是namespace.Service1,类似于endpoint元素的contract属性值需要是namespace.IService1,如下所示:
<services>
<service name="<namespace>.Service1" >
<endpoint address="" binding="basicHttpBinding"
bindingConfiguration="Service1"
contract="<namespace>.IService1" >
</endpoint>
</service>
</services>
只需替换Service1类的命名空间即可。这应该工作
答案 1 :(得分:0)