3

I have created in Visual Studio 2010 a C#/ASP.NET application, and in that a service.svc file and the corresponding

  • IService.cs //Contract
  • Service.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 //Contract
  • ServiceNew.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.

Redg
  • 399
  • 1
  • 6
  • 16
  • can you check that wsdl files are publishing properly when you try to call them using a web browser? – daryal Feb 12 '13 at 12:57
  • Are you running it on your developent machine? Does the event log give you more information? And how big is the dataset you are returning from the services? – Jocke Feb 12 '13 at 13:41
  • Yes I am running it on my development machine. I will update my post and also write the logs that I think you want. This logs are mentioned in the exception and on what it is shown in the browser when I run in debug mode my ServiceNew.svc file – Redg Feb 12 '13 at 13:48
  • Sorry, but I cant spot the error, so I'll keep asking questions: What settings for Reuse types in specified referenced assemblies do you use? http://msdn.microsoft.com/en-us/library/bb628653(v=vs.100).aspx – Jocke Feb 12 '13 at 14:29

3 Answers3

2

I´m not quite sure but you bind both services to same address, probably you have change the endpoint address for each service-implementation

<services>
 <service behaviorConfiguration="ServiceBehavior" name="Service">
   <endpoint address="a" binding="webHttpBinding"
       contract="IService" behaviorConfiguration="EndpBehavior"/>
 </service>
 <service behaviorConfiguration="ServiceBehavior" name="ServiceNew">
   <endpoint address="b" binding="webHttpBinding"
       contract="IServiceNew" behaviorConfiguration="EndpBehavior"/>
 </service>
  • I have tried what you just said with the addresses but again it throws the same error and the same exception is thrown when running the ServiceNew.svc in Debug (F5) – Redg Feb 12 '13 at 13:19
1

There is a bug which results in similar behavior of you are observing. I do not know whether this is the exact issue but you may check this support page.

daryal
  • 14,643
  • 4
  • 38
  • 54
1

I had the same problem with my service a few days back See here

The problem was that I could not have to services implementations int one .config file.

When I hosted the service I had to give the ServiceHost a type of the implementation - but since tow was defined in the config file it keep throwing an error.

My solution was to add one service from the config, and add the other (to a different ServiceHost) in C#

Community
  • 1
  • 1
Jens Kloster
  • 11,099
  • 5
  • 40
  • 54