WCF: KnownTypeAttribute missing in generated proxy - visual-studio

VS2013: WCF service and client.
Service contains class like:
[DataContract]
[KnownType(typeof(Class2))]
public class BaseClass1
{
...
}
When I generate client proxy using Visual studio 2013 'Update Service Reference' then proxy class does not contain KnownTypeAttribute of Class2.
But if I generate it manually using command string:
svcutil.exe http://localhost:8082/IService/mex /noConfig
the generated class has this attribute.
Also, VS2010 generates correct proxy class containing KnownTypeAttribute.
How to solve this problem?

Related

How to use Oracle Entity Framework with no config file

Is it possible to create a code-first Entity Framework model that connects to an existing database using ODP.Net without having any settings in the app.config file?
I have tried many different things.
Currently I am setting DbConfiguration:
sealed class EntityFrameworkConfiguration : DbConfiguration
{
public static readonly DbConfiguration Instance = new EntityFrameworkConfiguration();
EntityFrameworkConfiguration()
{
this.SetDefaultConnectionFactory(new OracleConnectionFactory());
this.SetProviderServices("Oracle.ManagedDataAccess.Client", EFOracleProviderServices.Instance);
}
}
DbConfiguration.SetConfiguration(EntityFrameworkConfiguration.Instance);
I am passing an OracleConnection directly into the EF context.
However, I either have problems with the SQL being generated in SQL Server format (using double-quotes around table aliases), or I get the following error:
An unhandled exception of type 'System.NotSupportedException' occurred in EntityFramework.dll
Additional information: Unable to determine the provider name for provider factory of type 'Oracle.ManagedDataAccess.Client.OracleClientFactory'. Make sure that the ADO.NET provider is installed or registered in the application config.
Has anyone any experience of getting this to work without polluting app.config with crud?
Yes. To complete the switch from machine.config/app.config to code-based configuration, I had to also include a call to SetProviderFactory().
public sealed class EntityFrameworkConfiguration : DbConfiguration
{
public static readonly DbConfiguration Instance = new EntityFrameworkConfiguration();
public EntityFrameworkConfiguration()
{
SetDefaultConnectionFactory(new OracleConnectionFactory());
SetProviderServices("Oracle.ManagedDataAccess.Client", EFOracleProviderServices.Instance);
SetProviderFactory("Oracle.ManagedDataAccess.Client", new OracleClientFactory());
}
}
I also called DbConfiguration.SetConfiguration(EntityFrameworkConfiguration.Instance); in the startup of my application because I had DbContext's in multiple assemblies that all needed to share this configuration.
On a side note, I have also found this to be effective in allowing your application to work around the ConfigurationErrorsException: The 'DbProviderFactories' section can only appear once per config file for cases where you may not have access to repair the user's machine.config.
Uff. Found the problem.
Because I was registering column mapping using lower case the query didn't work. The column and table names must be in upper-case.
How silly.

Visual Studio does not creates a proxy for OData v3 service

I have created an OData v3 service which includes EntityTypes with properties whose type is a collection (http://www.odata.org/documentation/odata-version-3-0/common-schema-definition-language-csdl#csdl5.1), for example:
<EntityType Name="Apps">
…
<Property Name="tags" Nullable="false" Type="Collection(Edm.String)"/>
…
</EntityType>
I have created a client for that service with Visual Studio (2012 and 2013) through right click in the project > Add Service Reference which creates a proxy class (AndroidContext in my example) for the service.
My problem is, when I try to retrieve an entity:
var app = androidContext.Apps.Where(a => a.Title == "Some title").First();
it throws an InvalidOperationException:
"Collection types are only supported in version 3.0 of the OData protocol and higher versions. They are not supported in version 2.0."
I have found that the proxy class created by Visual Studio has only one constructor which receives as only parameter the URI of the service. This constructor calls a base constructor (of the inherited class DataServiceContext) that use Odata v2 by default:
public DataServiceContext(Uri serviceRoot)
: this(serviceRoot, DataServiceProtocolVersion.V2)
{
}
I don’t understand why there is not a constructor that allows the creation of a proxy for OData v3. The solution I have used is to declare a new constructor for the proxy class (is partial) that allows OData v3:
public partial class AndroidContext
{
public AndroidContext(Uri serviceRoot, DataServiceProtocolVersion version) :
base(serviceRoot, version)
{
//The same that the generated constructor do
}
}
Does someone knows why Visual Studio does not allows the use of OData v3 by default? Does someone knows another solution?

Report Builder custom method of assembly returns "#Error"

I am currently trying to add an assembly into report builder 3.0 to execute a method and return the result:
But I always get "#Error" in the preview. Even whe the method is that simple:
public static string Test()
{
return "test";
}
Reference is set the following:
Expression is:
=TestNamespace.TestClass.Test()
The assembly is registered in GAC and it seems that the method is being checked for availableness. Elsewise I get a different error.
I finally fixed it.
Important is to set the following into AssemblyInfo.cs file:
using System.Security;
[...]
// added to use in Reporting Services
[assembly: AllowPartiallyTrustedCallers()]
More info:
http://www.sqlservercentral.com/blogs/dknight/2012/01/26/ssrs-custom-code-with-external-assemblies/
rsErrorLoadingCodeModule: what are the steps to deploy an assembly for use with Report Builder 2.0?
It is also not required to put the Assembly file in GAC. I simply put it here to test it locally:
C:\Program Files (x86)\Microsoft SQL Server\Report Builder 3.0

Make .dbml file in a class library use connectionstring from config file without subclassing it

I have a class library that is referenced from a web application. The class library defaults to using TestProject.Properties.Settings.Default.NFU_Custom_Website_DataConnectionString1. I would like it to get the connectionstring from ConfigurationManager.ConnectionStrings.
I can't change the .designer.cs file because it will get overwritten. If possible I would like to avoid creating a class which inherits from the .dbml file and setting the connection string in there. My boss recommends creating a web application project and deleting all of the default.aspx etc files from it and using that instead of a class library, is this a viable solution?
Thanks
Joe
You can do that. We had done that inadvertently and I got this problem when I switched to a class library. Rather than switch back I found the answer here: Point connectionstring in dbml to app.config
In summary:
Set the connection property of the DBML to (none) in the designer. This will remove the default constructor from the DB Context class.
Create a partial class for your DB Context with a default constructor:
using System.Configuration;
namespace TestProject
{
public partial class MyDBContext
{
public MyDBContext() : base(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString)
{
OnCreated();
}
}
}

AutoFac for Window Phone 7 - IContainter.Resolve extension method is not found

I'm building a fun application for Windows Phone 7. I'm using MVVM pattern and AutoFac for resolving the dependencies. I have got a classes AutoFacConfiguration holding a property as below
public static IContainer Container { get; private set; }
I try to resolve one of the registered types in some other part of the application like below
AutoFacConfiguration.Container.Resolve<IExpenseRepository>()
But this is not compiling. The compiler says Container does not have Resolve method. I know that IContainer derives from IComponentContext and an extension method with following signature does existing in the AutoFac assembly
public TService Resolve<TService>(this IComponentContext context)
Am I missing something here? I have just referenced the AutoFac.dll in my porject. This is downloaded from autofac site.
Have you added the relevant namespace as a using directive? For example, if the extension method is in class Foo.Bar.Baz, you should have:
using Foo.Bar;
in the source file that's trying to use the extension method.

Resources