I have created in Visual Studio 2010 a C#/ASP.NET application, and in that a service.svc
file and the corresponding
IService.cs
//ContractService.cs
//Implementation of the contract - interface
and this WCF service returns my data in JSON. I hit it with jQuery ajax post. This service seemed to work as I wanted it but then I decided to add a second service i.e. ServiceNew.svc
with its corresponding
IServiceNew.cs
//ContractServiceNew.cs
//Implementation of the contract - interface
and adding the corresponding endpoint in the web.config
.
After I added the second WCF service then none of the services worked it returned an 500 internal server error.
The most weird part is that if I remove from the folder of my application all the new files ServiceNew.svc
, IServiceNew.cs
, ServiceNew.cs
the first Service.svc
works when I hit them with jQuery posts as before, and then if I simply copy these files back again to my folder and run the Visual Studio host then BOTH of my services (old AND new) work for a random period of time and then they again suddenly return 500 error when I hit them with a jQuery ajax call.
My web.config
is:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="EndpBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="ServiceBehavior" name="Service">
<endpoint address="" binding="webHttpBinding"
contract="IService" behaviorConfiguration="EndpBehavior"/>
</service>
<service behaviorConfiguration="ServiceBehavior" name="ServiceNew">
<endpoint address="" binding="webHttpBinding"
contract="IServiceNew" behaviorConfiguration="EndpBehavior"/>
</service>
</services>
</system.serviceModel>
IService.cs
:
[ServiceContract]
public interface IService
{
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
[return: MessageParameter(Name = "d")]
MovieInfo GetMovieInfo(string title, string year);
}
Service.cs
:
[AspNetCompatibilityRequirements(RequirementsMode
= AspNetCompatibilityRequirementsMode.Allowed)]
public class Service: IService
{
public MovieInfo GetMovieInfo(string title, string year)
{
...
return MovieInfo();
}
}
Similarly
IServiceNew.cs
:
[ServiceContract]
public interface IServiceNew
{
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
[return: MessageParameter(Name = "d")]
string GetConf();
}
ServiceNew.cs
:
[AspNetCompatibilityRequirements(RequirementsMode
= AspNetCompatibilityRequirementsMode.Allowed)]
public class ServiceNew: IServiceNew
{
public string GetConf()
{
...
return conf;
}
}
Can someone tell me what am I doing wrong? How I can add more than one WCF services ( .svc files) in a ASP.NET application, in order to hit them with jQuery ajax calls?
Is something wrong with my web.config
?
Is it something else?
Thanks
UPDATE:
As an update I can say that when I try to Debug one of the .svc files, let's say the ServiceNew.svc in the browser the below exception is displayed:
Could not load file or assembly 'App_Web_oq2tdtg4, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
Stack Trace:
[FileNotFoundException: Could not load file or assembly 'App_Web_oq2tdtg4, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.] System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0 System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +39 System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks) +132 System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +144 System.Reflection.Assembly.Load(String assemblyString) +28 System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +210 System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +1461 System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +44 System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +651
[ServiceActivationException: The service '/ServiceNew.svc' cannot be activated due to an exception during compilation. The exception message is: Could not load file or assembly 'App_Web_oq2tdtg4, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified..] System.Runtime.AsyncResult.End(IAsyncResult result) +687598 System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +190 System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, String routeServiceVirtualPath, Boolean flowContext, Boolean ensureWFService) +234 System.ServiceModel.Activation.HttpHandler.ProcessRequest(HttpContext context) +24 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +100 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
Assembly Load Trace:
The following information can be helpful to determine why the assembly 'App_Web_oq2tdtg4, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' could not be loaded.
=== Pre-bind state information === LOG: User = ZULUTRADE\stassis LOG: DisplayName = App_Web_oq2tdtg4, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null (Fully-specified) LOG: Appbase = file:///C:/Users/stassis/Documents/Development/theDreamBox/ LOG: Initial PrivatePath = C:\Users\stassis\Documents\Development\theDreamBox\bin
Calling assembly : (Unknown).
LOG: This bind starts in default load context. LOG: Using application configuration file: C:\Users\stassis\Documents\Development\theDreamBox\web.config LOG: Using host configuration file: LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind). LOG: Attempting download of new URL file:///C:/Users/stassis/AppData/Local/Temp/Temporary ASP.NET Files/root/87ef3319/ec80b2f5/App_Web_oq2tdtg4.DLL. LOG: Attempting download of new URL file:///C:/Users/stassis/AppData/Local/Temp/Temporary ASP.NET Files/root/87ef3319/ec80b2f5/App_Web_oq2tdtg4/App_Web_oq2tdtg4.DLL. LOG: Attempting download of new URL file:///C:/Users/stassis/Documents/Development/theDreamBox/bin/App_Web_oq2tdtg4.DLL. LOG: Attempting download of new URL file:///C:/Users/stassis/Documents/Development/theDreamBox/bin/App_Web_oq2tdtg4/App_Web_oq2tdtg4.DLL. LOG: Attempting download of new URL file:///C:/Users/stassis/AppData/Local/Temp/Temporary ASP.NET Files/root/87ef3319/ec80b2f5/App_Web_oq2tdtg4.EXE. LOG: Attempting download of new URL file:///C:/Users/stassis/AppData/Local/Temp/Temporary ASP.NET Files/root/87ef3319/ec80b2f5/App_Web_oq2tdtg4/App_Web_oq2tdtg4.EXE. LOG: Attempting download of new URL file:///C:/Users/stassis/Documents/Development/theDreamBox/bin/App_Web_oq2tdtg4.EXE. LOG: Attempting download of new URL file:///C:/Users/stassis/Documents/Development/theDreamBox/bin/App_Web_oq2tdtg4/App_Web_oq2tdtg4.EXE.