我在配置maxRecievedMessageSite
的{{1}}属性时遇到了一些问题。我想创建一个端点来上传潜在的大文件,但是当前(我假设默认)限制是64K。对于图像和大型文档等项目,此限制不起作用。我已经从basicHttpBinding
创建了一个新的绑定,但是我一直在堆栈跟踪中得到错误,让我知道我已超出限制。下面我已经包含了我的配置文件,Global.asax文件,我的运营合同和我的服务实现中的相关部分。 (一切都非常简单,只是想让它发挥作用)。
配置文件
basicHttpBinding
Global.asax文件
<system.webServer>
<system.serviceModel>
<services>
<!-- CarImage Service Configuration -->
<service name="CarImageService">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="FileTransferServicesBinding"
contract="ICarImageService" />
</service>
</services>
<bindings>
<basicHttpBinding>
<!-- buffer: 64KB; max size: 64MB -->
<binding name="FileTransferServicesBinding"
closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="00:01:00"
sendTimeout="00:01:00"
transferMode="Streamed"
messageEncoding="Mtom"
maxBufferSize="999999"
maxReceivedMessageSize="67108864"
maxBufferPoolSize="99999">
<security mode="None" >
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
运营合同
namespace Mavizon.Mavia.Services
{
public class Global : HttpApplication
{
private string FilePath = ConfigurationManager.AppSettings["ImageFolder"];
void Application_Start(object sender, EventArgs e)
{
if (!Directory.Exists(FilePath))
{
Directory.CreateDirectory(FilePath);
}
RegisterRoutes();
}
private void RegisterRoutes()
{
RouteTable.Routes.Add(new ServiceRoute("test", new WebServiceHostFactory(), typeof(CarImageService)));
}
}
}
我的(非常)简单的实现类
namespace Mavizon.Mavia.Services.OperationContracts
{
[ServiceContract]
public interface ICarImageService
{
[OperationContract]
[FaultContract(typeof(ErrorFault))]
[WebInvoke(Method = "POST", UriTemplate = "/")]
void UploadImage(Stream request);
}
}
**这是我的堆栈跟踪信息**
namespace Mavizon.Mavia.Services.WebServices
{
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class CarImageService : OperationContracts.ICarImageService
{
public void UploadImage(Stream request)
{
}
}
}
**我正在制作的原始请求如下**
The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.
<StackTrace>
at System.ServiceModel.Channels.HttpInput.ThrowHttpProtocolException(String message, HttpStatusCode statusCode, String statusDescription)
at System.ServiceModel.Channels.HttpInput.ThrowMaxReceivedMessageSizeExceeded()
at System.ServiceModel.Channels.HttpInput.GetMessageBuffer()
at System.ServiceModel.Channels.HttpInput.ReadBufferedMessage(Stream inputStream)
at System.ServiceModel.Channels.HttpInput.ParseIncomingMessage(Exception&amp; requestException)
at System.ServiceModel.Channels.HttpRequestContext.CreateMessage()
at System.ServiceModel.Channels.HttpChannelListener.HttpContextReceived(HttpRequestContext context, Action callback)
at System.ServiceModel.Activation.HostedHttpTransportManager.HttpContextReceived(HostedHttpRequestAsyncResult result)
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest()
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest()
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequest(Object state)
at System.ServiceModel.AspNetPartialTrustHelpers.PartialTrustInvoke(ContextCallback callback, Object state)
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequestWithFlow(Object state)
at System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
</StackTrace><ExceptionString>System.ServiceModel.ProtocolException: The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.</ExceptionString><DataItems><Data><Key>System.ServiceModel.Channels.HttpInput.HttpStatusCode</Key><Value>BadRequest</Value></Data></DataItems></Exception></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>0</EventID><Type>3</Type><SubType Name="Transfer">0</SubType><Level>255</Level><TimeCreated SystemTime="2011-06-15T18:56:04.3623047Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{c05370d6-4c2f-4320-882f-365bf055e88f}" RelatedActivityID="{1782abf6-9c78-487d-91b0-29586d6140ad}" /><Execution ProcessName="WebDev.WebServer40" ProcessID="2268" ThreadID="5" /><Channel/><Computer>JOHNMURRAY027D</Computer></System><ApplicationData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>131085</EventID><Type>3</Type><SubType Name="Stop">0</SubType><Level>255</Level><TimeCreated SystemTime="2011-06-15T18:56:04.3623047Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{c05370d6-4c2f-4320-882f-365bf055e88f}" /><Execution ProcessName="WebDev.WebServer40" ProcessID="2268" ThreadID="5" /><Channel/><Computer>JOHNMURRAY027D</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Stop"><TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.ActivityBoundary.aspx</TraceIdentifier><Description>Activity boundary.</Description><AppDomain>f5dae6e-2-129526377562529297</AppDomain><ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord"><ActivityName>Processing message 1.</ActivityName><ActivityType>ProcessMessage</ActivityType></ExtendedData></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>131085</EventID><Type>3</Type><SubType Name="Resume">0</SubType><Level>255</Level><TimeCreated SystemTime="2011-06-15T18:56:04.3623047Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{1782abf6-9c78-487d-91b0-29586d6140ad}" /><Execution ProcessName="WebDev.WebServer40" ProcessID="2268" ThreadID="5" /><Channel/><Computer>JOHNMURRAY027D</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Resume"><TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.ActivityBoundary.aspx</TraceIdentifier><Description>Activity boundary.</Description><AppDomain>f5dae6e-2-129526377562529297</AppDomain><ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord"><ActivityName>Listen at 'http://localhost:2947/test'.</ActivityName><ActivityType>ListenAt</ActivityType></ExtendedData></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>0</EventID><Type>3</Type><SubType Name="Transfer">0</SubType><Level>255</Level><TimeCreated SystemTime="2011-06-15T18:59:36.5878906Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" RelatedActivityID="{a7f8d8f5-ff82-4283-9ea2-4eb8a55a51a5}" /><Execution ProcessName="WebDev.WebServer40" ProcessID="2268" ThreadID="5" /><Channel/><Computer>JOHNMURRAY027D</Computer></System><ApplicationData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>131085</EventID><Type>3</Type><SubType Name="Start">0</SubType><Level>255</Level><TimeCreated SystemTime="2011-06-15T18:59:36.5878906Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{a7f8d8f5-ff82-4283-9ea2-4eb8a55a51a5}" /><Execution ProcessName="WebDev.WebServer40" ProcessID="2268" ThreadID="5" /><Channel/><Computer>JOHNMURRAY027D</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Start"><TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.ActivityBoundary.aspx</TraceIdentifier><Description>Activity boundary.</Description><AppDomain>f5dae6e-2-129526377562529297</AppDomain><ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord"><ActivityName>Close ServiceHost 'Mavizon.Mavia.Services.WebServices.CarImageService'.</ActivityName><ActivityType>Close</ActivityType></ExtendedData></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>0</EventID><Type>3</Type><SubType Name="Transfer">0</SubType><Level>255</Level><TimeCreated SystemTime="2011-06-15T18:59:36.5878906Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{a7f8d8f5-ff82-4283-9ea2-4eb8a55a51a5}" RelatedActivityID="{00000000-0000-0000-0000-000000000000}" /><Execution ProcessName="WebDev.WebServer40" ProcessID="2268" ThreadID="5" /><Channel/><Computer>JOHNMURRAY027D</Computer></System><ApplicationData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>131085</EventID><Type>3</Type><SubType Name="Stop">0</SubType><Level>255</Level><TimeCreated SystemTime="2011-06-15T18:59:36.5878906Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{a7f8d8f5-ff82-4283-9ea2-4eb8a55a51a5}" /><Execution ProcessName="WebDev.WebServer40" ProcessID="2268" ThreadID="5" /><Channel/><Computer>JOHNMURRAY027D</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Stop"><TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.ActivityBoundary.aspx</TraceIdentifier><Description>Activity boundary.</Description><AppDomain>f5dae6e-2-129526377562529297</AppDomain><ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord"><ActivityName>Close ServiceHost 'Mavizon.Mavia.Services.WebServices.CarImageService'.</ActivityName><ActivityType>Close</ActivityType></ExtendedData></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>0</EventID><Type>3</Type><SubType Name="Transfer">0</SubType><Level>255</Level><TimeCreated SystemTime="2011-06-15T18:59:36.5878906Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{a7f8d8f5-ff82-4283-9ea2-4eb8a55a51a5}" RelatedActivityID="{1782abf6-9c78-487d-91b0-29586d6140ad}" /><Execution ProcessName="WebDev.WebServer40" ProcessID="2268" ThreadID="5" /><Channel/><Computer>JOHNMURRAY027D</Computer></System><ApplicationData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>0</EventID><Type>3</Type><SubType Name="Transfer">0</SubType><Level>255</Level><TimeCreated SystemTime="2011-06-15T18:59:36.5878906Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{1782abf6-9c78-487d-91b0-29586d6140ad}" RelatedActivityID="{a7f8d8f5-ff82-4283-9ea2-4eb8a55a51a5}" /><Execution ProcessName="WebDev.WebServer40" ProcessID="2268" ThreadID="5" /><Channel/><Computer>JOHNMURRAY027D</Computer></System><ApplicationData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>131085</EventID><Type>3</Type><SubType Name="Stop">0</SubType><Level>255</Level><TimeCreated SystemTime="2011-06-15T18:59:36.5878906Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{1782abf6-9c78-487d-91b0-29586d6140ad}" /><Execution ProcessName="WebDev.WebServer40" ProcessID="2268" ThreadID="5" /><Channel/><Computer>JOHNMURRAY027D</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Stop"><TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.ActivityBoundary.aspx</TraceIdentifier><Description>Activity boundary.</Description><AppDomain>f5dae6e-2-129526377562529297</AppDomain><ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord"><ActivityName>Listen at 'http://localhost:2947/test'.</ActivityName><ActivityType>ListenAt</ActivityType></ExtendedData></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent>
非常感谢任何帮助!
答案 0 :(得分:2)
两个问题:
您正在使用地址为“”的服务端点的WCF配置,但随后使用代码在“/ test”地址处使用ASP.NET路由来启动服务。您应该只需要将配置地址与要获取的端点配置的路由地址对齐。
您正在使用basicHttpBinding配置服务,但在运行时您指定将使用webHttpBinding(即REST支持)的WebServiceHostFactory
。您想将配置更改为webHttpBinding。如果它找到了您的服务的端点,那么接下来会遇到此错误,因为绑定类型会不匹配。
<强>更新强>
我今天早上意识到#1是不好的建议。实际上,您无法通过ServiceRoute
注册混合/匹配WCF服务/端点配置。因此,您有两种方法可以将特定绑定配置应用于ServiceRoutes
:
配置webHttpBinding
的默认值。这绝对是最简单的方法,因为它是所有配置,并且不需要对您正在进行的操作进行任何代码更改。请参阅下面的示例。
编写自定义WebServiceHostFactory
和WebServiceHost
子类,然后覆盖主机的创建并配置所需的特定绑定信息。当你要编写一堆服务项目时,这是一种更好的方法,因为不是所有项目都必须确保应用正确的配置条目,他们可以通过引用共享工厂实现做new MyWebServiceHostFactory()
。
默认绑定配置示例:
<system.serviceModel>
<bindings>
<webHttpBinding>
<!-- no name attribute on a binding means it's the default for the biding type -->
<binding transferMode="Streamed"
maxReceivedMessageSize="67108864">
<!-- other config here -->
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>