Solving: Could not load file or assembly ‘App_Web_squ1ikqu, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null’ or one of its dependencies. The system cannot find the file specified in .NET 4.0

After we virtualized a production machine and booted this virtualized machine, .NET reported some errors after re-registering .NET 4.0 on IIS7 these error where resolved, but one WCF service kept on logging the error:

Could not load file or assembly ‘App_Web_squ1ikqu, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null’ or one of its dependencies. The system cannot find the file specified.

 

Solution

The error was resolved after stopping all application pools in IIS7 and deleting the temporary internet files in the following folders:

  • C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files
  • C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files
  • C:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files
  • C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files

Determine the correct w3wp.exe process ID, to attach the Microsoft Visual Studio debugger to, by using the Windows Task Manager

If you have multiple application pools started in IIS 7 and you want to determine which w3wp.exe process to attach the Microsoft Visual Studio 2010 debugger to, you can use the Microsoft Windows Task Manager.

Start the Microsoft Windows Task Manager: press [Ctrl + Shift + Esc].

Add the columns "PID" and "Command Line" to the Process tab.

image

 

The name of the application pool will be shown in the Command Line Column.

In this case the WCF service I wanted to debug, was running on the default [ASP.NET v4.0] application pool.

The Microsoft Windows Task Manager, shows the PID of this w3wp.exe processes as 8188, so now I can attach the Microsoft Visual Studio debugger, to the process with ID 8188, to start debugging the WCF service

Using anonymous authentication on a .NET 4.0 WCF service that calls another WCF service

Let’s say you created a ASP .NET 4.0 website that uses a WCF service to get data from a Microsoft SQL Server database.

The website uses anonymous authentication and you are asked to show data on the website from another WCF service that use anonymous authentication:

 

image

 

By default wsHttpBinding uses windows authentication, so if you want to use wsHttpBinding in this scenario, you will have to disable authentication on both the WCF Server [A] binding as the WCF Service [B] binding.

This can be done, by setting the security mode to none on the binding and setting clientCredentialType to None on the transport and message nodes:

 

WCF Service [A] Web.config:

<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IMyServiceB" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
<security mode="None">
<transport clientCredentialType="None" />
<message clientCredentialType="None" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:64043/MyServiceB.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMyServiceB" contract="ADAICT.IMyServiceB" name="WSHttpBinding_IMyServiceB" />
</client>

 

WCF Service [B] Web.config

<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings>
<wsHttpBinding>
                <binding name="AnonymousBinding">
<security mode="None">
<transport clientCredentialType="None" />
<message clientCredentialType="None" />
</security>
</binding>
</wsHttpBinding>
</bindings>

 <service behaviorConfiguration="WcfServiceBehavior" name="MyServiceB">
<endpoint binding="wsHttpBinding" bindingConfiguration="AnonymousBinding"
contract="IMyServiceB" />
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<timeouts openTimeout="23:59:59" />
</host>
</service>

This allows the WCF Service [A] to communicate with WCF Service [B] on wsHttpBinding with anonymous access.

Solving: Object reference not set to an instance of an object, when calling a WCF service

 

I was getting a [Object reference not set to an instance of an object.] error, when calling a WCF service from a client application. The WCF service was build in [Any CPU] configuration, but an external dll was build in x86 modus. In this case the WCF service will only work, when you set the application pool property [Enable 32-Bit Applications] to True

image

 

 

 

Exception

[Object reference not set to an instance of an object.]
Server stack trace:
System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood
System.ServiceModel.Channels.ServiceChannel.HandleReply
System.ServiceModel.Channels.ServiceChannel.Call
System.ServiceModel.Channels.ServiceChannelProxy.InvokeService
System.ServiceModel.Channels.ServiceChannelProxy.Invoke
Exception rethrown[0]:
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke

How to solve: The WCF error “The service cannot be activated because it does not support ASP.NET compatibility” on IIS 7 and Windows 7

 

On IIS 7 and Windows 7, I got an error (see error below), when debugging mine WCF service.

Turned out I had to set [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] on mine service:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.ServiceModel.Activation;
namespace WcfService1
{
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}
}

 

 

Server Error in ‘/WcfService1’ Application.


The service cannot be activated because it does not support ASP.NET compatibility. ASP.NET compatibility is enabled for this application. Turn off ASP.NET compatibility mode in the web.config or add the AspNetCompatibilityRequirements attribute to the service type with RequirementsMode setting as ‘Allowed’ or ‘Required’.

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.InvalidOperationException: The service cannot be activated because it does not support ASP.NET compatibility. ASP.NET compatibility is enabled for this application. Turn off ASP.NET compatibility mode in the web.config or add the AspNetCompatibilityRequirements attribute to the service type with RequirementsMode setting as ‘Allowed’ or ‘Required’.

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:

[InvalidOperationException: The service cannot be activated because it does not support ASP.NET compatibility. ASP.NET compatibility is enabled for this application. Turn off ASP.NET compatibility mode in the web.config or add the AspNetCompatibilityRequirements attribute to the service type with RequirementsMode setting as 'Allowed' or 'Required'.]
System.ServiceModel.Activation.HostedAspNetEnvironment.ValidateCompatibilityRequirements(AspNetCompatibilityRequirementsMode compatibilityMode) +183896
System.ServiceModel.Description.DispatcherBuilder.ValidateDescription(ServiceDescription description, ServiceHostBase serviceHost) +441
System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost) +306
System.ServiceModel.ServiceHostBase.InitializeRuntime() +82
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +612
System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +287
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +1132
[ServiceActivationException: The service '/WcfService1/Service1.svc' cannot be activated due to an exception during compilation.  The exception message is: The service cannot be activated because it does not support ASP.NET compatibility. ASP.NET compatibility is enabled for this application. Turn off ASP.NET compatibility mode in the web.config or add the AspNetCompatibilityRequirements attribute to the service type with RequirementsMode setting as 'Allowed' or 'Required'..]
System.Runtime.AsyncResult.End(IAsyncResult result) +889824
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +179150
System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +136


Version Information: Microsoft .NET Framework Version:4.0.30128; ASP.NET Version:4.0.30128.

How to call and test SOAP or WCF services with complex types

Microsoft Visual Studio 2008 contains a SOAP and WCF test application [WcfTestClient], located at:

C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\WcfTestClient.exe

In the following screendumps I will test a SOAP service that uses latitude and longitude coordinates as parameters.

 

image

image

image

image

image

After clicking on Invoke:

image

image

.NET service (.svc) and “The page you are requesting cannot be served because of the extension configuration”

When you want to debug a .net service (*.svc) and you get the error: “The page you are requesting cannot be served because of the extension configuration”.

Try the solution on: http://tonytriguero.com/iis-7-and-webservices-svc-file-extension/

  • Open Visual Studio 2008 Command prompt.
  • Navigate to C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation
  • Run this command: servicemodelreg –i
  • Resolving the System.InvalidOperationException : Could not find default endpoint element that references contract ‘xxx’ in the ServiceModel client configuration section

    After renaming a WCF service reference in Microsoft Visual Studio, you can get the error:

    System.InvalidOperationException : Could not find default endpoint element that references contract ‘ImportServiceReference.IImportService’ in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
        at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)
        at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)
        at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)
        at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName)
        at System.ServiceModel.EndpointTrait`1.CreateSimplexFactory()
        at System.ServiceModel.EndpointTrait`1.CreateChannelFactory()
        at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait)
        at System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef()
        at System.ServiceModel.ClientBase`1..ctor()

    Make sure the name in the contract attribute of the endpoint is the same as you’re Microsoft Visual Studio Service Reference name

    <endpoint address="http://localhost/ImportService/ImportService.svc"
            binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IImportService"
    contract="ImportServiceReference.IImportService" name="WSHttpBinding_IImportService">
    <identity>
    <dns value="localhost" />
    </identity>
    </endpoint>

    Must be the same as:

    image