0

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..

  • What is "the opposite"? What do you do exactly when you get this error? – CodeCaster Jun 13 '18 at 07:46
  • @CodeCaster i try to make a query (SELECT) from my DB and i want to display the result in my webform. – mathieuvdc Jun 13 '18 at 07:48
  • No, that's not clear, please read [ask]. [Edit] your question to include a step-by-step description of what you do, what happens and what you have tried. There's probably simply occurring an exception somewhere. Debug your code. – CodeCaster Jun 13 '18 at 07:50
  • @CodeCaster Even if my question isn't as cleared as you expected, can you please try to give me some more precisions about this exception in this context ? – mathieuvdc Jun 13 '18 at 07:54
  • No, I can't guess which exception occurs. You need to debug your WCF service. – CodeCaster Jun 13 '18 at 07:56
  • @CodeCaster I have edited my post. But it's not complicated to understand... and my WCF works well for insert or delete, i just want explanations.. in general this exception means what in this context ?? Is that due to the fact that i'v not defined DataContract and DataMember annotations? – mathieuvdc Jun 13 '18 at 08:04
  • I'd rather expect the error to happen in the server. Did you add some execption handling and logging around the findTA method there? And do you see some error messages there? – Bernhard Hiller Jun 13 '18 at 08:13
  • 1
    This exception you receive on the client means that the server encountered an exception and closes the connection. It's no use guessing at the cause. Add logging or enable WCF tracing if you can't debug your service. – CodeCaster Jun 13 '18 at 08:16
  • @BernhardHiller No, i will do that right now. – mathieuvdc Jun 13 '18 at 08:19
  • @CodeCaster Thanks for your answer and your advice ! – mathieuvdc Jun 13 '18 at 08:19
  • Possible duplicate of [WCF Error "This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case"](https://stackoverflow.com/questions/2013880/wcf-error-this-could-be-due-to-the-fact-that-the-server-certificate-is-not-conf) – kenorb Oct 02 '18 at 16:24

0 Answers0