1

I'm under MVC 3, writing some classes used into a web service and they're also used in the app as entity. All is ok, but when the framework will generate the entities into the database, all SoapHeader attributes are also stored as table fields, ie:

  • EncodedMustUnderstand
  • EncodedMustUnderstand12
  • MustUnderstand
  • Actor
  • ...

Of course this happen because the base class of MyEntityClass is System.Web.Services.Protocols.SoapHeader.

My question is: how can I avoid the creation of soap header attributes into the db without doing manually (like NotMapped attributes)?

Here is my code

// MyEntityClass.cs
public class MyEntityClass : System.Web.Services.Protocols.SoapHeader
{
    // Attributes...
}

// MyService.asmx.cs
public class MyService : System.Web.Services.WebService
{
    public MyEntityClass myClass; // Used as header from the client

    [WebMethod]
    [System.Web.Services.Protocols.SoapHeader("myClass")]
    public string Hello()
    {
    }
}

Thanks guys!

1 Answers1

1

So, I post my own solution, may can be useful for someone otheer. I've just used, into my Entities (DbContect) class, the OnModelCreating method as shown below:

using System.Data.Entity;
namespace Application.Models
{
    public class Entities : DbContext
    {
        public DbSet<MyEntityClass> MyEntityClass { get; set; }
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Ignore<System.Web.Services.Protocols.SoapHeader>();
    }
}