i'm working on a Web Service using WCF and EntityFrameWork and an object called "TestsAuto". I'm using a WebForm to communicate with my localDB.
I have no problem to make INSERT, DELETE or UPDATE (sending a TestsAuto from my ASP.NET Web Form to a service's method which interacts whit my DB. But querying my DB to show the results on the Webform raises an Exception and i don't understand at all why.. Maybe it's a serialization problem, i've also heared about DataContract and DataMember but i really need the advices of an expert... ;) I am a beginner in these technologies.
This is the exception raised (i'm french):
Une exception de type 'System.ServiceModel.CommunicationException' s'est
produite dans mscorlib.dll mais n'a pas été gérée dans le code utilisateur
Informations supplémentaires : Une erreur s'est produite lors de la réception
de la réponse HTTP à http://localhost:13939/ServiceTA.svc. La raison peut en
être que la liaison de point de terminaison de service n'utilise pas le
protocole HTTP. Cela peut également être dû au fait qu'un contexte de requête
HTTP a été ignoré par le serveur.
Here's some samples of my code :
The class TestsAuto (generated by Entity with DataFirst) :
using System;
using System.Collections.Generic;
public partial class TestsAuto
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public TestsAuto()
{
this.Resultats = new HashSet<Resultat>();
}
public int testid { get; set; }
public string nom { get; set; }
public string perimetre { get; set; }
public string si { get; set; }
public string intorrec { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Resultat> Resultats { get; set; }
My Interface and the implementation of the specific method:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace WcfService1
{
[ServiceContract]
public interface IServiceTA
{
[OperationContract]
void insertTA(TestsAuto ta);
[OperationContract]
void insertRes(Resultat res);
[OperationContract]
void insertCom(Commentaire com);
[OperationContract]
void insertParam(Param param);
[OperationContract]
void updateTA(TestsAuto ta);
[OperationContract]
int updateRes(Resultat res);
[OperationContract]
int updateCom(Commentaire com);
[OperationContract]
int updateParam(Param param);
[OperationContract]
void deleteTA(TestsAuto ta);
[OperationContract]
int deleteRes(Resultat res);
[OperationContract]
int deleteCom(Commentaire com);
[OperationContract]
int deleteParam(Param param);
[OperationContract]
TestsAuto findTA(int id);
[OperationContract]
TestsAuto findRes(int id);
[OperationContract]
TestsAuto findCom(int id);
[OperationContract]
List<TestsAuto> listTA();
[OperationContract]
List<Resultat> listRes();
[OperationContract]
List<Commentaire> listCom();
[OperationContract]
List<Param> listParam();
}
}
the method :
public TestsAuto findTA(int id)
{
return tee.TestsAutoes.Single(p => p.testid == id);
}
The code of the WebForm :
protected void btnSelect_Click(object sender, EventArgs e)
{
ServiceTAClient client = new ServiceTAClient();
TestsAuto taa = client.findTA(20);
}
Step-by-Step : -> I've created the WCF service with the code above. -> I've create a model with EF - DataFirst. -> I've created a simple webform to try CRUD operations and i added the ServiceReference. -> INSERT, UPDATE AND DELETE are working with no problems but If i want to SELECT it raises an exception.
Thanks, i think this is not a huge problem but i didn't find any answers on the web..