Exposing wcf service in BizTalk 2010 - wcf

I have ran into this issue the past few weeks ago and I still can not figure out why.
I have a BizTalk orchestration that receives a BizTalk message, processes it and eventually writes it to a file. For simplicity sake, let say, our goal is to take the message (which is actually a survey) and save it to a folder as is. I have created a public receive port to catch the msg and a send port to write the result out to disk.
I have successfully deployed the project and have successfully published it to IIS. I was able to see the WCF service in IIS and have set it to use Framework 4.0. I have set up all the relevant receive and send ports and have started the application successfully from BizTalk management console. (The receive location was automatically created when I published the wcf service, the send location is a type FILE located in a folder in the computer)
From DefaultSite in IIS, I could see my WCF. However, when I tried http://localhost/TestSurvey/TestSurvey_Orchestration_1_getSurveyPort.svc,
I got the following error:
Server Error in '/TestSurvey' Application.
--------------------------------------------------------------------------------
Login failed for user 'Domain\ComputerName$'.
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.Data.SqlClient.SqlException: Login failed for user 'ACAD1\DENBIZDEV$'.
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:
[SqlException (0x80131904): Login failed for user 'Domain\ComputeName$'.]
[TargetInvocationException: Exception has been thrown by the target of an invocation.]
Microsoft.BizTalk.TransportProxy.Interop.IBTTransportProxy.RegisterIsolatedReceiver(String url, IBTTransportConfig callback) +0
Microsoft.BizTalk.Adapter.Wcf.Runtime.WcfIsolatedReceiver`2.RegisterIsolatedReceiver(Uri uri) +1028
Microsoft.BizTalk.Adapter.Wcf.Runtime.WebServiceHostFactory`3.CreateServiceHost(String constructorString, Uri[] baseAddresses) +363
System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +1413
System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +50
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +1172
[ServiceActivationException: The service '/TestSurvey/TestSurvey_Orchestration_1_getSurveyPort.svc' cannot be activated due to an exception during compilation. The exception message is: Exception has been thrown by the target of an invocation..]
System.Runtime.AsyncResult.End(IAsyncResult result) +901424
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +178638
System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +107
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
My question is: what is it that BizTalk was trying to login? Domain\ComputerName$ is definitely not a user. I have not tried to access any database from the orchestration. I believe my IIS was set up correctly as I have created a quick and dirty wcf service test from VS2010 and published it to my IIS, then have successfully created a simple client to consume the wcf service test. I did not encounter the same issue when I created the wcf service test directly.
Any help or hint is highly appreciated!
EDIT
I managed to fix this: it was not the web config as it was created by BizTalk. I had to create a special app pool and tied my application to using it. In the app pool I have to use the custom credential that BizTalk is using. Using the built in credentials caused the issue I experienced. My rookie error! Once BizTalk login credential was used, everything went smoothly.

The database which is throwing the SQL exception is one of the BizTalk databases, probably the management or SSO DB.
The error is almost certainly being caused by the setup of IIS, whether the app pool identity or the web site security settings.
What is hapenning is that when you call the service for the first time IIS is compiling your service, and to do this it obviously needs access to one of the BizTalk databases, but this call is not authenticated for some reason.
This could be because the app pool user must be a member of the BizTalk Isolated Host Users group (which may be called something different depending on how BizTalk was set up.

Related

ASP.Net Core Web API in IIS

I'm trying to add an API to IIS. The API (via Swagger) runs fine locally. To rule out anything in my API I built the basic Weather API one and I get the same error.
App Log:
Application '/LM/W3SVC/1/ROOT/WeatherAPI' with physical root 'C:\inetpub\wwwroot\Weather' failed to load coreclr. Exception message:
CLR worker thread exited prematurely
Application '/LM/W3SVC/1/ROOT/WeatherAPI' with physical root 'C:\inetpub\wwwroot\Weather' hit unexpected managed exception, exception code = '0xe0434352'. Please check the stderr logs for more information.
Error 0xe0434352 is so generic as to be of no use.
I see others have had similar issues (some of which are on StackOverflow) but none resolve the issue.
It's being published as: Release/.Net 6.0/Self-Contained/win-x64.
The AppPool is "No Managed Code"/Integrated Pipedline.

WCF Service hosted in Azure Cloud Service errors after published

I have a project with several WCF services (mix of REST and SOAP). The project has been running On-Prem for 6 months without an issue. We are moving this to Azure but have run into an issue that will prevent us from going live.
The project uses Autofac for it's IOC. We are gonig to host this in a Cloud Service in Azure. Everything appears to work correctly when running locally in the Azure Emulator however once we deploy using the Cloud Service project, everything builds and deploys correctly, but we receive the following error when trying to access a service.
Server Error in '/' Application.
Value cannot be null. Parameter name: key
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: key 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: key]
System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument) +48
System.Collections.Generic.Dictionary`2.FindEntry(TKey key) +38
System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value) +20
System.ServiceModel.Dispatcher.WebHttpDispatchOperationSelector..ctor(ServiceEndpoint endpoint) +2459
System.ServiceModel.Description.WebHttpBehavior.GetOperationSelector(ServiceEndpoint endpoint) +125
System.ServiceModel.Description.WebHttpBehavior.ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) +1955
System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost) +4245
System.ServiceModel.ServiceHostBase.InitializeRuntime() +119
System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) +45
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +553
System.ServiceModel.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity) +350
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +1614
[ServiceActivationException: The service '/Event/Calendar' cannot be activated due to an exception during compilation. The exception message is: Value cannot be null.
Parameter name: key.]
System.Runtime.AsyncResult.End(IAsyncResult result) +925
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +528
System.ServiceModel.Activation.AspNetRouteServiceHttpHandler.EndProcessRequest(IAsyncResult result) +107
System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +151
It appears that it's having an issue with the service configuration endpoint. That is registered through Autofac WCF integration using the OOTB RouteTable here:
RouteTable.Routes.Add(new ServiceRoute("Event/Calendar", new AutofacWebServiceHostFactory(), typeof(CalendarSvc)));
All of this works fine in IIS and the local Azure emulator, but once deployed to the cloud service is where we get an issue.
Observed exactly problem. Solved by canceling IntelliTrace on this hosted service.
I did publishing from VS2013 and marked "Enable IntelliTrace" during publishing. Once I canceled this option and re-publish - all works properly....

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"/>

HELP! - DefaultServiceHostFactory executing before application_startup and container creation

I am using the WCF facility for a service hosted in WAS (net.tcp binding in iis7) and experiencing a weird issue only upon a cold application startup (i.e. not already running).
The following statement should be executed upon first instantiation of my container.
DefaultServiceHostFactory.RegisterContainer(c.Kernel);
When the service is requested, I get the following exception in my WCF tracefile
Kernel was null, did you forgot to call DefaultServiceHostFactory.RegisterContainer()
The issue appears to be that the ServiceHostFactory is attempting to create an instance of the service's host before my container has been created.
Note:
This exception is happening BEFORE the Application_Start is executed
If the application is running (and the container has been initialised) then the service will operate as expected. The application can be started by going to the appropriate IIS site over HTTP or starting a debugging session from Visual Studio.
Steps to recreate issue
Issue a IISReset to shutdown all IIS app pools.
Call the service in question
WCF tracing spits out:
System.ServiceModel.ServiceActivationException: The service '/abcd.svc' cannot be activated due to an exception during compilation. The exception message is: Exception has been thrown by the target of an invocation.. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentNullException: Kernel was null, did you forgot to call DefaultServiceHostFactory.RegisterContainer() ?
Parameter name: kernel
at Castle.Facilities.WcfIntegration.WindsorServiceHostFactory`1..ctor(IKernel kernel)
at Castle.Facilities.WcfIntegration.DefaultServiceHostFactory..ctor()
The problem is that global.asax and all its methods are related only to HTTP processing. Btw. class in global.asax is derived from HttpApplication which should make this pretty clear. Once you host application in WAS (which is case of net.tcp based binding) you can't use these methods. Try to use something like AppInitialize.

WCF service hosted in IIS throws 'Failed to access IIS metabase' error

Deployed a WCF service in IIS 6.0 gave NETWORK_sERVICE user read/write privileges.
When tries to brows to .SVC file i get below error
Failed to access IIS metabase.
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.Web.Hosting.HostingEnvironmentException: Failed to access IIS metabase.
The process account used to run ASP.NET must have read access to the IIS metabase (e.g. IIS://servername/W3SVC). For information on modifying metabase permissions, please see http://support.microsoft.com/?kbid=267904.
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:
[HostingEnvironmentException: Failed to access IIS metabase.]
System.Web.Configuration.MetabaseServerConfig.MapPathCaching(String siteID, VirtualPath path) +637
System.Web.Configuration.MetabaseServerConfig.System.Web.Configuration.IConfigMapPath2.MapPath(String siteID, VirtualPath vpath) +9
System.Web.Hosting.HostingEnvironment.MapPathActual(VirtualPath virtualPath, Boolean permitNull) +174
System.Web.Hosting.HostingEnvironment.MapPathInternal(VirtualPath virtualPath, Boolean permitNull) +51
System.Web.CachedPathData.GetConfigPathData(String configPath) +341
System.Web.CachedPathData.GetConfigPathData(String configPath) +234
System.Web.CachedPathData.GetApplicationPathData() +38
System.Web.CachedPathData.GetVirtualPathData(VirtualPath virtualPath, Boolean permitPathsOutsideApp) +8806383
System.Web.Configuration.RuntimeConfig.GetLKGRuntimeConfig(VirtualPath path) +117
Any thoughts?
Was told that we get 'Failed to access IIS metabase' error if we install IIS after intalling .NET Framework, and remedy is to re-install ASP.NET.
To resolve this error I have followed below steps
1. Stopped IIS
2. Ran below command in command prompt to re-install aspnet.
%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i
Result:
Start installing ASP.NET (2.0.50727).
..................................................................
Finished installing ASP.NET (2.0.50727).
3. Re-started IIS and WCF service is responding without any issues.