我对 WCF 有疑问。
第一个应用程序是我从站点this编写的示例。它运作良好。
我需要制作一个应用程序来从数据库的服务器列表中传输对象。但是当我得到客户列表时,以下内容CommunicationException
:
接收到 (localhost:8080) 的 HTTP 响应时出错。这可能是由于服务端点绑定未使用 HTTP 协议。这也可能是由于服务器中止了 HTTP 请求上下文(可能是由于服务关闭)。有关更多详细信息,请参阅服务器日志。
服务器运行良好,或者我不明白的东西。
如果你需要关于项目的信息(代码),我会给它
对不起我的英语不好。
UPD:配置:
<?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>
服务器代码:
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:
失败:
MobilePostsClient mpc = new MobilePostsClient();
var list = mpc.GetAllPosts();
MobilePostClient
由Add Service Reference
.
UPD3:IMobilePosts:
[ServiceContract]
public interface IMobilePosts
{
[OperationContract]
List<Post> GetAllPosts();
[OperationContract]
FullPost GetFullPost(int postId);
}
移动帖子:
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);
}
}
存储库工作正常。