Unity Configuration in Referenced Assembly not recognized - wcf

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.

Related

Using ChannelFactory with WorkflowServiceHost

Is there a way to do the service inference on a workflow definition XAML to create an interface that can be distributed to the client to be used with ChannelFactory instead of the host exposing WSDL and the client having to generate a service definition by adding a service reference?
I did this in a three step process:
Temporarily exposing the metadata from the workflow service
Creating proxy code with svcutil
Changing configuration back to not exposing metadata
In detail:
Include your XAMLX file which defines the service in a project that was created as "WCF Workflow Service Application" (DeclarativeServiceLibrary1)
Compile the project
Set the project as startup project
Select xamlx file in Solution Explorer
Press Ctrl-F5 -> WCF Test Client starts, you see your service loaded
RightClick on the xamlx URL in WCF Test Client, choose Copy address (e.g. http://localhost:56326/Service1.xamlx)
Open a VS2010 Admin console window
Create the proxy code with svcutil.exe:
cd /D %TEMP%
svcutil http://localhost:56326/Service1.xamlx
This creates two files, a *.cs and a *.config, that contain the proxy code
I had a lot of problems with other ways of craeting the proxy code (inside VS2010), the external svcutil was the most stable way to do it. Hope this helps.

WCF Enterprise Library ExceptionHandling failing when faultcontracttype in other project

Background: I have a WCF project that is using Microsoft Enterprise Library WCF Exception Handling.
We recently decided to move our operation and data contracts into a separate project (.net assembly) called comanynamespace.xxx.WCF.Utilities. After moving the operation and data contracts, I changed the faultContractType namespace to reflect the new assembly.
Now when I launch the web service in VS2010 I get the following error:
Activation error occured while trying to get instance of type ExceptionPolicyImpl, key "WCF Exception Shielding"
I have tried: ensuring the same references exist in both projects and ensuring that both projects are running under .net 4 (no client modes), etc. Neither helped resolve the issue.
Finally, I copied the Service Fault class back into the Web Service project and changed the namespace in the web.config to point back to the local namespace:
from:
faultContractType="comanynamespace.xxx.WCF.Utilities.ServiceFault, comanynamespace.xxx.WCF.Utilities.Services"
to:
faultContractType="comanynamespace.xxx.Web.Services.ServiceFault, comanynamespace.xxx.Web.Services"
This does resolve the error, however, now I must have my service fault data contract in both locations.
Does anyone know why I am unable to use a service fault (data contract) in another .net assembly with Microsoft EL WCF Exception Handling?
The problem ended up being that the namespace (second part) of the faultcontracttype was set to
faultContractType="companyname.xxx.WCF.Utilities.Services.ServiceFault, companyname.xxx.WCF.Utilities.Services"
instead of
faultContractType="companyname.xxx.WCF.Utilities.Services.ServiceFault, companyname.xxx.WCF.Utilities"
companyname.xxx.WCF.Utilities is the namespace for the assembly.

Use of WebServiceHost2Factory

What is the use of "WebServiceHost2Factory".
I am creating Rest Wcf service.
I am using VS2010 so do I need to install WCF Rest Starter Kit??
When I added WebServiceHost2Factory to my service markup I am getting an error saying
"The CLR Type 'Microsoft.ServiceModel.Web.WebServiceHost2Factory' could not be loaded during service compilation".
What am I missing here.
here is my markUp for Service.
<%# ServiceHost Language="C#" Debug="true" Service="WCFRESTService1.Service1" CodeBehind="Service1.svc.cs" Factory = "Microsoft.ServiceModel.Web.WebServiceHost2Factory" %>
Any help will be appreciated.
Use WebServiceHost2Factory and WebProtocolException for Error Handling
A large part of building an API is ensuring there is adequate error handling in place to help the user implement your API. Up until the release of WebServiceHost2Factory, returning the appropriate HTTP response code and message was a chore. Luckily for us we can achieve this feat quickly and easily by utilising the WebServiceHost2Factory and WebProtocoException classes.
The above text is from the following link
The below help to troubleshoot your problem can be found from the following link.
Parser Error: Service Type Could Not Be Loaded During Compilation
You may get the following error message when you navigate a WCF service (.svc file) from a browser:
The CLR Type 'XXXX' could not be loaded during service compilation. Verify that this type is either defined in a source file located in the application's \App_Code directory, contained in a compiled assembly located in the application's \bin directory, or present in an assembly installed in the Global Assembly Cache. Note that the type name is case-sensitive and that the directories such as \App_Code and \bin must be located in the application's root directory and cannot be nested in subdirectories.
The error message is pretty explainable by itself. However, I still want to point out different situations when this can happen. Here is the format of the Service Directive of a .svc file:
<%#Service language=c# Class="<Managed Type>" [Other attributes] %>
Here are possible reasons why this can happen:
The specified string for the “Class” attribute does not represent an existing CLR type. Sometimes, this may be due to a typo. This string is case-sensitive. Also if you copy this from MS-Word, the quotes may be some special Unicode characters instead of the real ASCII quotes.
If you have the assembly (containing the service type) in the \bin directory, it is possible that you did not create a virtual directory so that its root directory contains \bin as its immediate sub-directory.
If you have your type in a code file under \App_Code, it may be due to the same reason as above.

Connection string in app.config in a class library

I am creating solution and inside I have three projects:
A WCF Service Library Project
A DataAccess Project (Class Library)
A Web site for hosting WCF service
The implementation of the service is on the project # 1, but in order to access the DataBase I use a second project that implements the data access using a class library project.
That problem is in order to get data access I need to configure a connection string, but that connection string must be configurable in a production environment, I meant in production I am going to deploy the site, which is a very simple project that contains only a reference WCF Service Library Project then a guy from database department will configure the connection string.
In development I have an app.config on the data access project but when I do the release that app.config is embedded on the dll.
Any ideas how can we achieve our purpose
The connection string must be in the application configuration file of the executing assembly. This means that you can provided the configuration file for your assembly along with the assembly itself but anyone who wants to use your assembly must update their configuration file to include the values that your assembly relies on.
The connection string in your app.config (data layer) is not embedded in the dll.
If you look in the app.config file in your data layer project, you will probably have a connectionStrings section. you need to put the connectionStrings in the web.config of your WCF service website.
This can be configured in your production environment.
I had a mistake, I was using a different name on the web.config of the WCF site, I just copy the the exact part of the app.config to the web.config and its working now.
Thanks for your help

Silverlight Business Application template with WCF is throwing warning

I am using the Silvelight Business Application template. I wrote a function which uses Membership.getUserList function to return the user list. I tried exposing it as Service using WCF. But when I try to compile the client side code it throws a warning saying "Client Proxy Generation for user_authentication.Web.Service1 failed'. Why does it happen?
The complete warning message is:
Warning 4 Client proxy generation for
service
'user_authentication.Web.Service1'
failed: Generating metadata files...
Warning: Unable to load a service with
configName
'user_authentication.Web.Service1'. To
export a service provide both the
assembly containing the service type
and an executable with configuration
for this service.
Details:Either none of the assemblies passed were executables
with configuration files or none of
the configuration files contained
services with the config name
'user_authentication.Web.Service1'.
Warning: No metadata files were
generated. No service contracts were
exported. To export a service, use
the /serviceName option. To export
data contracts, specify the
/dataContractOnly option. This can
sometimes occur in certain security
contexts, such as when the assembly is
loaded over a UNC network file share.
If this is the case, try copying the
assembly into a trusted environment
and running it.
Hard to say, I'm not a good enough clairvoyant yet ;-) ... Is your webservice actually already compiled, published and running? Maybe here you can find further hints:
MSDN WCF Forums: svcutil Error