我有一个在虚拟机上运行的WCF服务。我已经有一段时间没有更改此服务器或服务上的任何内容了。当我尝试通过约25 mb的服务发送文件时,我得到了:
----------------------------------------------------------
DateTime: 1/24/2019 12:22:04 PM
ClassName: UploadPpsZipFile
Message: There was no endpoint listening at http://www.myservice.com/xxx/FileService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
Server stack trace:
at System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.GetOutputStream()
at System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout)
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.SendRequest(Message message, 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 WebStorageFileTransfer.TruckTransferServiceReference.IFileService.UploadPpsZipFile(UploadFileRequest uploadFileRequest)
at WebStorageFileTransfer.ProgramTypes.SendZip.SendZip_Upload.UploadPpsZipFile(FileParms fileParms)
Unable to connect to the remote server
at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
at System.Net.HttpWebRequest.GetRequestStream()
at System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.GetOutputStream()
An attempt was made to access a socket in a way forbidden by its access permissions xxx.xxx.xxx.xxx:80
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
----------------------------------------------------------
我的app.exe.config看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IFileService" maxReceivedMessageSize="2147483647" sendTimeout="00:02:00">
<readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://www.myservice.com/xxxx/FileService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IFileService" contract="TruckTransferServiceReference.IFileService" name="BasicHttpBinding_IFileService" />
</client>
</system.serviceModel>
</configuration>
当我发送一个较小的文件(例如1mb文件)时,我没有任何问题。我已经在多台计算机上对此进行了测试,并且得到了相同的结果。
有什么建议吗?
答案 0 :(得分:0)
您可以更改3件事以使其正常工作:
IIS主机设置:
我相信您已经在IIS中托管了WCF服务。因此,您需要设置 发送大量数据时,您需要设置maxAllowedContentLength IIS设置(有关更多信息,请参阅配置IIS Request Limits) 据我所知,该值默认为〜28MB。
接收的最大邮件大小:
您将不得不将此值更改为其他值(例如long.MaxValue)。默认情况下,它设置为64 KB。
启用流式传输
默认情况下,WCF的传输模式是缓冲的。在发送和接收所有数据时,需要将所有数据存储在内存中-这对于大文件是不可能的。
因此,您必须将模式更改为“流式”,如下所示:
<system.serviceModel>
…
<bindings>
<basicHttpBinding>
<binding name="ExampleBinding" transferMode="Streaming"/>
</basicHttpBinding>
</bindings>
…
<system.serviceModel>