I've just spend the afternoon reading almost every post on Stack Overflow about WCF and streaming. I am still getting an error which I cannot trace. Below is my client and server definitions and the error I'm getting. If anybody can either point me to a post that will solve my issue or provide me with an answer it would be greatly appreciated. If I change to transferMode="Buffered" then everything works (if the files are small enough). This feels like something small I'm missing ...
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>
Exception :
... 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, 开发者_C百科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: ...
精彩评论