OData WCF service suddenly starts to return 404 on .Net 4.0 - wcf

We have an OData WCF service running on some customers servers. Everything worked very well on .Net 3.5, but after having upgraded our solution to .Net4, the WCF service suddenly starts returning 404 for all requests after random time intervals, usually several days.
The rest of the web site is running normally. The 404's appear to be happening after the website has restarted.
In order to make it work again, we have make a change in web.config. Calling HttpRuntime.UnloadAppDomain(); fails to fix the problem.
We're trying to reproduce the error locally, but since it sometimes takes several days before it happens, it's a difficult problem to reproduce.
Any suggestions?
EDIT:
This is the error message from the server event log:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="System.ServiceModel 4.0.0.0" />
<EventID Qualifiers="49154">3</EventID>
<Level>2</Level>
<Task>5</Task>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2012-06-02T11:15:32.000000000Z" />
<EventRecordID>28236</EventRecordID>
<Channel>Application</Channel>
<Computer>xxxx-ST-001</Computer>
<Security UserID="S-1-5-82-3945269471-185734930-3707521103-2442450153-1755958218" />
</System>
- <EventData>
<Data>System.ServiceModel.Activation.HostedHttpRequestAsyncResult/65092316</Data>
<Data>System.Web.HttpException (0x80004005): There was no channel actively listening at 'http://11.11.11.11/waf/services/OData.svc'. This is often caused by an incorrect address URI. Ensure that the address to which the message is sent matches an address on which a service is listening. ---> System.ServiceModel.EndpointNotFoundException: There was no channel actively listening at 'http://11.11.11.11/waf/Services/OData.svc'. This is often caused by an incorrect address URI. Ensure that the address to which the message is sent matches an address on which a service is listening. at System.ServiceModel.Activation.HostedHttpTransportManager.HttpContextReceived(HostedHttpRequestAsyncResult result) at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest() at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest() at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result) at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result)</Data>
<Data>w3wp</Data>
<Data>1852</Data>
</EventData>
Update 18.december 2012:
We're able to reproduce the error locally by making sure the first request to the site after a restart is made to the WCF OData service. The error message:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
System.Web.Compilation.DiskBuildResultCache.CacheBuildResult(String cacheKey, BuildResult result, Int64 hashCode, DateTime utcStart) +9508708
System.Web.Compilation.BuildManager.CacheBuildResultInternal(String cacheKey, BuildResult result, Int64 hashCode, DateTime utcStart) +70
System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) +9929866
System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) +299
System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) +103
System.Web.Compilation.BuildManager.GetVPathBuildResult(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean ensureIsUpToDate) +82
System.Web.Compilation.BuildManager.GetCompiledCustomString(String virtualPath) +29
System.ServiceModel.HostingManager.GetCompiledCustomString(String normalizedVirtualPath) +164
System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +206
System.ServiceModel.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity) +52
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +598
[ServiceActivationException: The service '/ecoodata' cannot be activated due to an exception during compilation. The exception message is: Object reference not set to an instance of an object..]
System.Runtime.AsyncResult.End(IAsyncResult result) +495736
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +178
System.ServiceModel.Activation.ServiceHttpModule.EndProcessRequest(IAsyncResult ar) +348782
System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +9663393
Anyone got a clue what this might be?

Related

Value cannot be null exception when trying to run Imageresizer

I get the following error when trying to run my Image Resizer using my rest api plugin with this urL: http://localhost:8001/D1900010012059
Plugin code can be found here: https://github.com/mikaelekstrom/resizerapiplugin/blob/master/RestAPIImageRetriever.cs
Value cannot be null.
Parameter name: value
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: value
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentNullException: Value cannot be null.
Parameter name: value]
System.String.StartsWith(String value, StringComparison comparisonType) +598
ImageResizer.Storage.BlobProviderBase.FileExists(String virtualPath, NameValueCollection queryString) +88
ImageResizer.Plugins.VirtualPathProviderShim.GetVIP(String virtualPath) +217
ImageResizer.Plugins.VirtualPathProviderShim.FileExists(String virtualPath) +23
System.Web.Routing.RouteCollection.IsRouteToExistingFile(HttpContextBase httpContext) +120
System.Web.Routing.RouteCollection.GetRouteData(HttpContextBase httpContext) +129
System.Web.Routing.UrlRoutingModule.PostResolveRequestCache(HttpContextBase context) +70
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +139
System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +195
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +88
You need to set the VirtualFilesystemPrefix property on the base class to set up routing for your class. You class will handle all requests going to that prefix.

entlib wcf integration is throwing exception when trying to pass argument by reference

using the Enterprise Library in a WCF service application, we encounter the following exception when we try to use validation on an operation that has arguments passed in by reference:
The operation contract:
Hubs GetRoute(
string sourceDepotId,
[NotNullValidator(MessageTemplate = "...")]
[RegexValidator("[a-zA-Z]", MessageTemplate = "...")]
[StringLengthValidator(2, RangeBoundaryType.Inclusive, 2, RangeBoundaryType.Inclusive, MessageTemplate = "...")]
string countryCode,
string zipCode,
DateTime shippingDate,
DateTime? deliveryDate,
ref RoutingCodes routingCode,
out string errorMessage);
The exception:
The type 'RoutingCodes&' may not be used as a type argument.
[ArgumentException: The type 'RoutingCodes&' may not be used as a type argument.]
System.RuntimeType.ThrowIfTypeNeverValidGenericArgument(RuntimeType type) +14240432
System.RuntimeType.SanityCheckGenericArguments(RuntimeType[] genericArguments, RuntimeType[] genericParamters) +57
System.RuntimeType.MakeGenericType(Type[] instantiation) +218
Microsoft.Practices.EnterpriseLibrary.Validation.ValidatorFactory.WrapAndInstrumentValidator(Validator validator, Type type) +87
Microsoft.Practices.EnterpriseLibrary.Validation.ValidatorFactory.FindOrCreateValidator(ValidatorCacheKey cacheKey, Func`3 wrapAndInstrument) +190
Microsoft.Practices.EnterpriseLibrary.Validation.ValidatorFactory.CreateValidator(Type targetType, String ruleset) +176
Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF.ValidationParameterInspector.CreateInputParameterValidator(ParameterInfo param, String ruleSet) +99
Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF.ValidationParameterInspector..ctor(OperationDescription operation, String ruleSet) +221
Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF.ValidationBehavior.ApplyDispatchBehavior(ContractDescription contractDescription, ServiceEndpoint endpoint, DispatchRuntime dispatchRuntime) +161
System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost) +5106
System.ServiceModel.ServiceHostBase.InitializeRuntime() +85
System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) +48
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +293
System.ServiceModel.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity) +129
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +733
The type stated is a enumeration type. I know that you actually can pass arguments by ref in WCF and it works, as stated in the documentation.
Is this a bug in the Enterprise Library Validation Block or what are we doing wrong? How do you circumvent the exception besides not using the validation block?

WCF Can't Open MSMQ Queue: Access is Denied

We have a Windows Service which uses WCF to reads messages from an MSMQ queue. Recently, the service won't start because it can't open the queue:
Running WcfHost, service contract IWcfService. :
System.InvalidOperationException: There was an error opening the queue. Ensure
that MSMQ is installed and running, the queue exists and has proper authorization
to be read from. The inner exception may contain additional information. --->
System.ServiceModel.MsmqException: An error occurred while opening the queue:
Access is denied. (-1072824283, 0xc00e0025). The message cannot be sent or
received from the queue. Ensure that MSMQ is installed and running. Also ensure
that the queue is available to open with the required access mode and
authorization.
at System.ServiceModel.Channels.MsmqQueue.OpenQueue()
at System.ServiceModel.Channels.MsmqQueue.GetHandle()
at System.ServiceModel.Channels.MsmqQueue.SupportsAccessMode(String formatName, Int32 accessType, MsmqException& msmqException)
--- End of inner exception stack trace ---
at System.ServiceModel.Channels.MsmqVerifier.VerifyReceiver(MsmqReceiveParameters receiveParameters, Uri listenUri)
at System.ServiceModel.Channels.MsmqTransportBindingElement.BuildChannelListener[TChannel](BindingContext context)
at System.ServiceModel.Channels.Binding.BuildChannelListener[TChannel](Uri listenUriBaseAddress, String listenUriRelativeAddress, ListenUriMode listenUriMode, BindingParameterCollection parameters)
at System.ServiceModel.Description.DispatcherBuilder.MaybeCreateListener(Boolean actuallyCreate, Type[] supportedChannels, Binding binding, BindingParameterCollection parameters, Uri listenUriBaseAddress, String listenUriRelativeAddress, ListenUriMode listenUriMode, ServiceThrottle throttle, IChannelListener& result, Boolean supportContextSession)
at System.ServiceModel.Description.DispatcherBuilder.BuildChannelListener(StuffPerListenUriInfo stuff, ServiceHostBase serviceHost, Uri listenUri, ListenUriMode listenUriMode, Boolean supportContextSession, IChannelListener& result)
at System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost)
at System.ServiceModel.ServiceHostBase.InitializeRuntime()
at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at WcfHost`2.Open()
We've double-checked the queue's permissions and they haven't changed. We've run ProcMon and aren't seeing any access denied events. We don't know what changed to cause this error.
Why can't WCF open this queue?
You can try turn off RPC request from queue settings?

WCF Application "Unable to find assembly" for SQLite

Note: This is a solved problem, but I just spend 4 hours at this issue, so I wanted to share the solution.
When I attempt to access a WCF service, the service never responds, and the event log shows the following:
An unhandled exception occurred and
the process was terminated.
Application ID: DefaultDomain
Process ID: 3180
Exception:
System.Runtime.Serialization.SerializationException
Message: Unable to find assembly
'System.Data.SQLite, Version=1.0.66.0,
Culture=neutral,
PublicKeyToken=db937bc2d44ff139'.
StackTrace: at
System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly()
at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo
assemblyInfo, String name) at
System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String
objectName, String[] memberNames,
BinaryTypeEnum[] binaryTypeEnumA,
Object[] typeInformationA, Int32[]
memberAssemIds, ObjectReader
objectReader, Int32 objectId,
BinaryAssemblyInfo assemblyInfo,
SizedArray assemIdToAssemblyTable)
at
System.Runtime.Serialization.Formatters.Binary._BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped
record) at
System.Runtime.Serialization.Formatters.Binary._BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum
binaryHeaderEnum) at
System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler
handler, __BinaryParser serParser,
Boolean fCheck, Boolean
isCrossAppDomain, IMethodCallMessage
methodCallMessage) at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream
serializationStream, HeaderHandler
handler, Boolean fCheck, Boolean
isCrossAppDomain, IMethodCallMessage
methodCallMessage) at
System.Runtime.Remoting.Channels.CrossAppDomainSerializer.DeserializeObject(MemoryStream
stm) at
System.AppDomain.Deserialize(Byte[]
blob) at
System.AppDomain.UnmarshalObject(Byte[]
blob)
Solution
In my case, the problem ended up being a simple incorrect database path. However, the error message in no way reflects the actual cause, so YMMV.
The reason the "bad connection string" exception didn't make it to the event log seems related to this KB article. If the connection string isn't your problem, then your best course may be to follow the steps in this article, which will cause IIS to write exceptions to the event log.

OAuth Consumer request for token from ServiceProvider returns InternalServerError

I'm playing around with DevDefined.OAuth - an OAuth consumer and provider implementation for .Net http://code.google.com/p/devdefined-tools/wiki/OAuth and on launching the ExampleConsumerSite project after configuring the service endpoints on my IIS 7 web server, I'm receiving the following error:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Exception: Request for uri: http://localhost:8080/RequestToken.aspx?oauth_callback=oob&oauth_nonce=94efde0b-dd45-4cee-8253-7496cef0b877&oauth_consumer_key=key&oauth_signature_method=PLAINTEXT&oauth_timestamp=1252512419&oauth_version=1.0&oauth_token=&oauth_signature=secret%2526 failed.
status code: InternalServerError
An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Source Error:
[HttpException]: 'RequestToken' is not allowed here because it does not extend class 'System.Web.UI.Page'.
at System.Web.UI.TemplateParser.ProcessError(String message)
at System.Web.UI.TemplateParser.ProcessInheritsAttribute(String baseTypeName, String codeFileBaseTypeName, String src, Assembly assembly)
at System.Web.UI.TemplateParser.PostProcessMainDirectiveAttributes(IDictionary parseData)
[HttpParseException]: 'RequestToken' is not allowed here because it does not extend class 'System.Web.UI.Page'.
at System.Web.UI.TemplateParser.ProcessException(Exception ex)
at System.Web.UI.TemplateParser.ParseStringInternal(String text, Encoding fileEncoding)
at System.Web.UI.TemplateParser.ParseString(String text, VirtualPath virtualPath, Encoding fileEncoding)
[HttpParseException]: 'RequestToken' is not allowed here because it does not extend class 'System.Web.UI.Page'.
at System.Web.UI.TemplateParser.ParseString(String text, VirtualPath virtualPath, Encoding fileEncoding)
at System.Web.UI.TemplateParser.ParseReader(StreamReader reader, VirtualPath virtualPath)
at System.Web.UI.TemplateParser.ParseFile(String physicalPath, VirtualPath virtualPath)
at System.Web.UI.TemplateParser.ParseInternal()
at System.Web.UI.TemplateParser.Parse()
at System.Web.UI.TemplateParser.Parse(ICollection referencedAssemblies, VirtualPath virtualPath)
at System.Web.Compilation.BaseTemplateBuildProvider.get_CodeCompilerType()
at System.Web.Compilation.BuildProvider.GetCompilerTypeFromBuildProvider(BuildProvider buildProvider)
at System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders()
at System.Web.Compilation.BuildProvidersCompiler.PerformBuild()
at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)
at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert)
at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert)
at System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)
at System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)
at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
I've noticed the oauth_token GET parameter is empty. On tracing this, the error source is from the line 12 of Default.aspx.cs page:
IToken requestToken = session.GetRequestToken();
protected void oauthRequest_Click(object sender, EventArgs e)
{
OAuthSession session = CreateSession();
IToken requestToken = session.GetRequestToken();
if (string.IsNullOrEmpty(requestToken.Token))
{
throw new Exception("The request token was null or empty");
}
Session[requestToken.Token] = requestToken;
string callBackUrl = "http://localhost:" + HttpContext.Current.Request.Url.Port + "/Callback.aspx";
string authorizationUrl = session.GetUserAuthorizationUrlForToken(requestToken, callBackUrl);
Response.Redirect(authorizationUrl, true);
}
While I'm not sure if this has to do with configuring the service endpoints but I'm running the consumer project from VS2008 and hosting the service on IIS. Please advice.
Working now. Error was due to the page RequestToken.aspx in the OAuthChannel not inheriting the correct class behind so when the consumer site was making a request for a token that resulted in an internal server error on the ServiceProvider side.