VS2010, WCF Service wouldn't start - wcf

I will go through what i've done so far step by step as below:
created empty solution
added a website WCFService
deleted the Service and IService from the website
added a WCF service library project to the solution
added end points to the web.config
did the same in app.config
added a reference to the service library in the web application
ctrl + F5
9
I get the following error:
Server Error in '/WFLedger'
Application. The type
'Services.WFLedger.WF_Ledger',
provided as the Service attribute
value in the ServiceHost directive, or
provided in the configuration element
system.serviceModel/serviceHostingEnvironment/serviceActivations
could not be found. 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
type
'Services.WFLedger.WF_API_Ledger',
provided as the Service attribute
value in the ServiceHost directive, or
provided in the configuration element
system.serviceModel/serviceHostingEnvironment/serviceActivations
could not be found.
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 type
'Services.WFLedger.WF_Ledger',
provided as the Service attribute
value in the ServiceHost directive, or
provided in the configuration element
system.serviceModel/serviceHostingEnvironment/serviceActivations
could not be found.]
System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String
constructorString, Uri[]
baseAddresses) +654
System.ServiceModel.HostingManager.CreateService(String
normalizedVirtualPath) +1439
System.ServiceModel.HostingManager.ActivateService(String
normalizedVirtualPath) +45
System.ServiceModel.HostingManager.EnsureServiceAvailable(String
normalizedVirtualPath) +647
[ServiceActivationException: The
service '/WFLedger/WF_Ledger.svc'
cannot be activated due to an
exception during compilation. The
exception message is: The type
'Services.WFAPILedger.WF_API_Ledger',
provided as the Service attribute
value in the ServiceHost directive, or
provided in the configuration element
system.serviceModel/serviceHostingEnvironment/serviceActivations
could not be found..]
System.Runtime.AsyncResult.End(IAsyncResult
result) +437
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult
result) +188
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication
context, String
routeServiceVirtualPath, Boolean
flowContext, Boolean ensureWFService)
+230 System.ServiceModel.Activation.HttpModule.ProcessRequest(Object
sender, EventArgs e) +360
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
+213 System.Web.HttpApplication.ExecuteStep(IExecutionStep
step, Boolean& completedSynchronously)
+76
this is really driving me crazy!!!
why am i getting this error?
if you need more information please let me know so that i provide them to you
thanks a million in advance

Look at the WF_Ledger.svc file in your web site project. It should only consist of one line. There'll be Service attribute containing "Services.WFAPILedger.WF_API_Ledger". WCF is looking for the "Services.WFAPILedger.WF_API_Ledger" class but not finding it. The namespace and class name need to either exist in the web site project or be a reference as you're trying to set up. You'll need to edit that Service attribute to match the service implementation class in the WCF service library project.

Please check if the .svc file is provided and is of the following form.
<% #ServiceHost Language=C# Debug="true" Service="MyService" CodeBehind="~/App_Code/Service.cs" %>
Its all one line and the file should contain nothing else.

Try to add new default service then check newly added works fine.
If yes, check web.config endpoint contract name provided,
and in .svc file check code behind mentioned correctly.

In .svc file Service parameter should include namespace followed by class name i.e. it should be in the format mynamespace.myservice

Build the WCF project and try again. This error may occur because of the absence of a DLL in bin folder.
For me building and trying again resolved it.

Even make sure that, In your .svc file directive, The "service" attribute's value is fully qualified class name, i.e example: if your namespace is like "ns1.ns2.ns3.ClassName" (where ns1, ns2,ns3 are namespaces).

This error can be generated by renaming a class name in the *.svc.cs file without renaming it in the *.svc markup.
Two ways to resolve this problem:
Rename the class name to the original name.
Rename the service reference in the markup (right click in *.svc file, then click "View Markup"*).
Your markup code looks like this:
<%# ServiceHost Language="C#" Debug="true" Service="WCFSample.MyClass"CodeBehind="MyClass.svc.cs" %>
*Note: I had this problem in VS2017, don't know if that option is in VS2010.

check the function name and parameter in Iservice class where you calling the function and checkout your Service class also where function is define..

Related

Unity Configuration in Referenced Assembly not recognized

I have a rather expensive library which I've inherited from another project. This assembly is using interception via Unity and requires an elaborate Web.config for design time configuration. I am attempting to use this assembly from within a MSMQ WCF Service, and I'm receiving errors when the code inside the assembly attempts to open DB connections that are hosted by Enterprise Library.
Resolution of the dependency failed, type =
"ServicesImplementation.EntityMaster.IEntityRepository", name =
"(none)". Exception occurred while: while resolving. Exception is:
InvalidOperationException - The current type,
ServicesImplementation.EntityMaster.IEntityRepository, is an interface
and cannot be constructed. Are you missing a type mapping?
My question, is it required that I assume all configuration responsibilities from my WCF Service, or is this configuration encapsulated within the referenced assembly.
You must include all configuration in your .config file. It is defalult source for application to get it config data. Also notice, that if you host in IIS, you should use web.config, if not(Windows Service or app) - use app.config. It is possible to extract section configuration to another file and reference it from your main config.
For example:
Assembly1 contains service definition and host logic.
Assembly2 actualy hosts Assembly1 service.
In this case all service configuration must reside in Assembly2 *.config file.

registring a wcf service with Castle Windsor

I have a very simple service which works fine when not using Castle (which shows that the other codes are correct).
I changed my svc file to the following:
<%# ServiceHost Service="Reporting.WebService.ReportingWebService" Factory="Castle.Facilities.WcfIntegration.DefaultServiceHostFactory, Castle.Facilities.WcfIntegration" %>
and register the service using xml as follow:
<component id="Reporting.WebService.ReportingWebService"
service="Reporting.WebService.IReportingWebService, Reporting.WebService"
type="Reporting.WebService.ReportingWebService, Reporting.WebService">
</component>
But I am getting the following error:
[InvalidOperationException: Could not find a component with name Reporting.WebService.ReportingWebService, did you forget to register it?] Castle.Facilities.WcfIntegration.WindsorServiceHostFactory`1.CreateServiceHost(String constructorString, Uri[] baseAddresses)
....
Any idea why it is not registered? ?
----update ----
I have this in windsor configuration:
<facilities>
<facility id='wcf'
type='Castle.Facilities.WcfIntegration.WcfFacility,
Castle.Facilities.WcfIntegration' />
</facilities>
and ReportingWebService is implimented in another assembly.
I cannot see anything wrong with the wire up which leads me to think that either it cannot find your assembly or maybe the type has not been loaded. Because your webservice is referenced in another assembly make sure that it is referenced in the web project. Alternatively switch to doing your wire up in your Global.asax in code which will force you to reference the assembly and load the type:
var container = new WindsorContainer();
container.AddFacility<WcfFacility>()
.Register(Component.For<IReportingWebService>().ImplementedBy<ReportingWebService>());
//Additional wire up
//If you are using Windsor 3.0 and above then the following is not needed
DefaultServiceHostFactory.RegisterContainer(container.Kernel);

WCF - weird error

I have my dll hosted at IIS with wsHttpBinding. I have this weird error happened intermediate.
Well, everything will be restored back normal again when I reset the IIS (iisreset).
I also read this one http://msdn.microsoft.com/en-us/library/ee517280.aspx. But I am not sure it has to do with this. Please guide me if you more info on this. Thanks.
Server Error in '/MSBuildCompilation' Application.
Either a required impersonation level was not provided, or the
provided impersonation level is invalid. (Exception from HRESULT:
0x80070542) 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.Runtime.InteropServices.COMException: Either
a required impersonation level was not provided, or the provided
impersonation level is invalid. (Exception from HRESULT: 0x80070542)
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:
[COMException (0x80070542): Either a required impersonation level was
not provided, or the provided impersonation level is invalid.
(Exception from HRESULT: 0x80070542)]
[FileLoadException: Could not load file or assembly
'System.ServiceModel, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' or one of its dependencies. Either a
required impersonation level was not provided, or the provided
impersonation level is invalid. (Exception from HRESULT: 0x80070542)]
System.ServiceModel.Activation.HttpModule.ProcessRequest(Object
sender, EventArgs e) +0
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
+148 System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously) +75
Looks like you are trying to run the .NET 4.0 Framework in IIS6 which be tricky according to this post. Haven't tried that myself. The exception you are getting is actually happening because your process is unsuccessfully trying to load the System.ServiceModel version 4.0 DLL. Although that post is for ASP.NET, it's applicable to WCF because ASP.NET is the service host process in IIS6. Here is another question along the same lines with some good answers.
(Answered by original poster but in wrong place, moved by me.)
Hi all, I finally solved my own problem by adding this 2 lines at my Client Application code:
WindowsClientCredential wsCred = wsFactory.Credentials.Windows;
wsCred.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
This 2 lines to force client to impersonate every time when it connects.

No compatible TransportManager error

Answer
It was a configuration problem.
We had two services in the application. Prior to the problem, both services had explicit binding configuration that matched and worked well. One service was going to be removed, so the dev remmed out the explicit binding configuration, forgetting that .NET 4.0 provides default (and different) bindings.
Whichever service was hit first, its settings would not be incompatible with any other settings (since it was first) and would be fine. The service that was loaded subsequently would have different binding settings and be refused by the TransportManager.
The apparent intermittency was due to us only focusing on the one remaining service, thinking the other service was no longer in the picture. A monitoring utility was still hitting the removed service and would get in sometimes before we could reload the other service after a configuration change.
Original Question
We're getting an intermittent error when first starting up a service in IIS. If I make a whitespace change to any of the configs and reload, then about 50% of the time the service will come up fine. Once it's up, it's good to go. But the next time we deploy to this box, we start the russian roulette all over again.
We've looked over other forum posts on the same error and so far have not been able to come up with a definite fix. It took us a while to realize that none of the configuration changes we were trying were actually influencing the problem since merely a whitespace change is enough to get it to start afresh and get it to work part of the time. Seems there's some sort of race condition internally with the TransportManagerTable, perhaps it's empty when the service fails to come up? Not sure, trying to get some tracing or something to give us better info on what's in the TransportManagerTable instance.
There is no compatible TransportManager found for URI 'net.tcp://box:10101/DEV/AwesomeService.svc'. This may be because that you have used an absolute address which points outside of the virtual application, or the binding settings of the endpoint do not match those that have been set by other services or endpoints. Note that all bindings for the same protocol should have same settings in the same application.
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: There is no compatible TransportManager found for URI 'net.tcp://box:10101/DEV/AwesomeService.svc'. This may be because that you have used an absolute address which points outside of the virtual application, or the binding settings of the endpoint do not match those that have been set by other services or endpoints. Note that all bindings for the same protocol should have same settings in the same application.
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: There is no compatible TransportManager
found for URI 'net.tcp://box:10101/DEV/AwesomeService.svc'. This may
be because that you have used an absolute address which points outside
of the virtual application, or the binding settings of the endpoint do
not match those that have been set by other services or endpoints.
Note that all bindings for the same protocol should have same settings
in the same application.]
System.ServiceModel.Channels.TransportChannelListener.ThrowTransportManagersNotFound()
+8955459 System.ServiceModel.Channels.TransportChannelListener.SelectTransportManagers()
+16199511 System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTransportManagersCallback
selectTransportManagerCallback) +71
System.ServiceModel.Channels.TcpChannelListener`2.OnOpen(TimeSpan
timeout) +182
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan
timeout) +789
System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan
timeout) +375
[InvalidOperationException: The ChannelDispatcher at
'net.tcp://box:10101/DEV/AwesomeService.svc' with contract(s)
'"IAwesomeService", "ILoggingService"' is unable to open its
IChannelListener.]
System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan
timeout) +16199205
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan
timeout) +789 System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan
timeout) +126
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan
timeout) +789
System.ServiceModel.HostingManager.ActivateService(String
normalizedVirtualPath) +287
System.ServiceModel.HostingManager.EnsureServiceAvailable(String
normalizedVirtualPath) +1132
[ServiceActivationException: The service '/DEV/AwesomeService.svc'
cannot be activated due to an exception during compilation. The
exception message is: The ChannelDispatcher at
'net.tcp://box:10101/DEV/AwesomeService.svc' with contract(s)
'"IAwesomeService", "ILoggingService"' is unable to open its
IChannelListener..] System.Runtime.AsyncResult.End(IAsyncResult
result) +890624
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult
result) +180062
System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult
ar) +107
Version Information: Microsoft .NET Framework Version:4.0.30319;
ASP.NET Version:4.0.30319.1
Edited the configuration to set the Address Empty and the error was fixed.
To add a little bit more instruction, the issue is most likely in the Web.Config file of your service. In the node, make sure that your Endpoint Address is an empty string -or- make sure that your Endpoint Address URL points to the exact location of your service, as you specified in IIS.
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="MyServiceBinding" contract="MySolution.IMyService"/>

WCF: referencing a service from script manager issue

I'm working from a project on localhost:2971 and in the master page i want to include an asp:ScriptReference to a wcf service i am hosting in IIS at localhost:5152
<Services>
<asp:ServiceReference InlineScript="false" Path="http://localhost:5152/CostService.svc" />
</Services>
then i attempt to call:
var service = new SandwichServices.CostService();
service.CostOfSandwiches(5, onSuccess);
on a page that inherits from the master page.
however, in the firefox error console i get the following:
Error: no element found
Source File: http://localhost:2971/CostService.svc/CostOfSandwiches
Line: 1
So why is the source file pointing to 2971?
the service works fine on the sample page i created on 2152.
Anyone know whats up?
Any help would be much appreciated!
<!--
[EndpointNotFoundException]: The service '/CostService.svc' does not exist.
at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)
at System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast(String relativeVirtualPath)
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest()
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest()
[HttpException]: The service '/CostService.svc' does not exist.
at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result)
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, Boolean flowContext)
at System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
-->
I would think you are developing using Cassini (Web Server Inside VS). You need two instances of Cassini to have access to the 2 ports you are talking about. If it was IIS the portnumber is not required.