我只是花了一个下午阅读Stack Overflow关于WCF和流媒体的几乎所有帖子。我仍然收到一个我无法追查的错误。下面是我的客户端和服务器定义以及我得到的错误。如果有人能指出我将解决我的问题的帖子或给我一个答案,我将不胜感激。如果我改为transferMode =“Buffered”,那么一切正常(如果文件足够小)。这感觉就像我失踪的小东西......
的Web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- 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 -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings>
<basicHttpBinding>
<binding name="Streamer" maxReceivedMessageSize="67108864" transferMode="Streamed"/>
</basicHttpBinding>
</bindings>
<services>
<service name="MyService">
<endpoint address="/" binding="basicHttpBinding" bindingConfiguration="Streamer" contract="IService1" />
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
的App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="Streamer" maxReceivedMessageSize="67108864" transferMode="Streamed" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:52316/Service1.svc" binding="basicHttpBinding" bindingConfiguration="Streamer"
contract="Service1Reference.IService1" />
</client>
</system.serviceModel>
</configuration>
例外:
... System.ServiceModel.ProtocolException was unhandled Message=The remote server returned an unexpected response: (400) Bad Request. Source=mscorlib StackTrace:
Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException, ChannelBinding channelBinding)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at MyClient.Service1Reference.IService1.UploadFile(UploadFileMessage request)
at MyClient.Service1Reference.Service1Client.MyClient.Service1Reference.IService1.UploadFile(UploadFileMessage request) in c:\temp\WCFSTREAM\MyClient\Service References\Service1Reference\Reference.cs:line 87
at MyClient.Service1Reference.Service1Client.UploadFile(String fileName, String key, Stream fileData) in c:\temp\WCFSTREAM\MyClient\Service References\Service1Reference\Reference.cs:line 95
at MyClient.Program.Main(String[] args) in c:\temp\WCFSTREAM\MyClient\Program.cs:line 24
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart() InnerException: System.Net.WebException
Message=The remote server returned an error: (400) Bad Request.
Source=System
StackTrace:
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
InnerException: ...