C# Channelfactory can't retrieve model objects from WCF Service

736 Views Asked by At

Currently, I'm trying to realise a server-client program. The models used in this project are defined in a shared assembly and are beeing marked with the attribute DataContract. The server should use them as well as the client so there's no need to produce code twice. When the client starts a request to the server it should return an instance of the shared model to make sure it can use the methods and constructors as well as the data.

The server is realised with a WCF-Service. On client side, the data should be retrieved via a channelfactory, not via a .wsdl-file.

Client side:

    private void TestSzenarioOne()
    {
        var address = new EndpointAddress($"http://{Host}:{Port1}/{ServiceName}");
        var binding = new BasicHttpBinding();
        var factory = new ChannelFactory<ITestInterface>(binding, address);
        var channel = factory.CreateChannel();
        var test1 = channel.DoStringTest(); // <-- works fine
        var test2 = channel.DoStringEnumerableTest(); // <-- works fine
        var test3 = channel.DoTest(); // <-- want to get List<User> error!!!! 
    }

Service contract shared library:

[ServiceContract]
public interface ITestInterface: IDisposable
{
    [OperationContract]
    IEnumerable<User> DoTest();

    [OperationContract]
    string DoStringTest();

    [OperationContract]
    IEnumerable<User> DoStringEnumerableTest();

The connection from the WCF service is open and i can access the service via url.

Why i can't get model objects from the server? Any Idea:

Error: CommunicationException

Error receiving the HTTP response for http : // localhost : 1800 / testService service . The cause may be that the service endpoint binding not using the HTTP protocol . Another possible cause is that the HTTP request context is aborted by the server ( probably due to the shutdown of the service ) . More information can be found in the server logs . "

User class:

[KnownType(typeof(Entity))]
[DataContract]
public class User : Entity
{
    [DataMember]
    public string Name { get; set; }

    [DataMember]
    public string ShortName { get; set; }

    [DataMember]
    public string Password { get; set; }
}

Entity:

[DataContract]
public class Entity
{
    [DataMember]
    public long Id { get; } = 0;
}
0

There are 0 best solutions below