I has a problem with WCF.
The first application I wrote the example from the site this. It worked good.
I need to make an application to transfer objects from the server list from the database. But when I get a list of the client, the following CommunicationException
:
An error occurred while receiving the HTTP response to (localhost:8080). This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.
Server worked good or I do not understand something.
If you need information (code) on the project will be, I will give it
Sorry for my English.
UPD: config:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service name="Habra.Server.MobilePosts" behaviorConfiguration="MyBehavior">
<endpoint
address=""
binding="basicHttpBinding"
contract="Habra.Core.IMobilePosts" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Castle.Core" publicKeyToken="407dd0808d44fbdc" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
server code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Habra.Server
{
using System.ServiceModel;
public class Program
{
public static void Main(string[] args)
{
Type serviceType = typeof(MobilePosts);
Uri serviceUri = new Uri("http://localhost:8080/");
ServiceHost host = new ServiceHost(serviceType, serviceUri);
host.Open();
foreach (Uri uri in host.BaseAddresses)
{
Console.WriteLine("\t{0}", uri.ToString());
}
Console.WriteLine();
Console.WriteLine("Number of dispatchers listening : {0}", host.ChannelDispatchers.Count);
foreach (System.ServiceModel.Dispatcher.ChannelDispatcher dispatcher in host.ChannelDispatchers)
{
Console.WriteLine("\t{0}, {1}", dispatcher.Listener.Uri.ToString(), dispatcher.BindingName);
}
Console.WriteLine();
Console.WriteLine("Press <ENTER> to terminate Host");
Console.ReadLine();
}
}
}
UPD2:
fails in:
MobilePostsClient mpc = new MobilePostsClient();
var list = mpc.GetAllPosts();
MobilePostClient
created by Add Service Reference
.
UPD3: IMobilePosts:
[ServiceContract]
public interface IMobilePosts
{
[OperationContract]
List<Post> GetAllPosts();
[OperationContract]
FullPost GetFullPost(int postId);
}
MobilePosts:
public class MobilePosts : IMobilePosts
{
private readonly IRepository repository = new RepositoryQueries();
public List<Post> GetAllPosts()
{
var list = this.repository.GetAllPosts();
foreach (Post post in list)
{
Console.WriteLine(post.Title + " loading...");
}
return list;
}
public FullPost GetFullPost(int postId)
{
return this.repository.GetFullPostById(postId);
}
}
Repositories worked correct.
Did you set attributes to Post class properties?
You can trace all messages with ServiceBehavior read more here.
i.e. put attribute to servie
and set trace output to file