WCF服务错误无配置文件或端点.net 3.5
问题描述:
我正在编写WCF服务 - 客户端。该服务正在将端点URL作为arg获取,这是Windows窗体应用程序。
的服务IMPL是:WCF服务错误无配置文件或端点.net 3.5
BaseAddress = new Uri(args[0]);
using (ServiceHost host = new ServiceHost(typeof(DriverService), BaseAddress))
{
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
host.Description.Behaviors.Add(smb);
//host.AddServiceEndpoint(typeof(DriverService), new BasicHttpBinding(), BaseAddress);
host.Open();
后host.Open()我得到的错误,当我写了另一种解决方案相同的WCF的代码,它的工作就好了,我有客户端和服务。现在我只需要等到客户端连接时才打开服务。
据我所知,这是服务,我给它的地址,然后它监听给定的地址,并暴露接口上的方法,以不同的客户端。
错误:
接口和类的Service 'DriverHost.DriverService' has zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element.
代码:
[ServiceContract]
public interface IDriverService
{
[OperationContract]
string WhoAmI();
}
public class DriverService : IDriverService
{
public string WhoAmI()
{
return string.Format("Im on port !");
}
}
答
,因为有不同的.NET 4.5和3.5之间我明白没有默认的端点。
所以需要声明:
BaseAddress = new Uri(args[0]);
using (ServiceHost host = new ServiceHost(typeof(Namespace.Classname), BaseAddress))
{
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
host.Description.Behaviors.Add(smb);
host.AddServiceEndpoint(typeof(Namespace.IInterface), new BasicHttpBinding(), args[0]);
host.Open();
意义 - 添加.AddServiceEndpoint(..) 并确保在ServiceHost的()写的类,并且在AddServiceEndpoint输入接口。
你有绑定在你的app.config – DaveHogan 2013-03-18 10:28:03
我没有在我的app.config,但在我做的样本,我没有写任何绑定 – ilansch 2013-03-18 10:31:23
这可能是重复http://stackoverflow.com/questions/2807525/wcf-self-host-service-endpoints-in -c-sharp?rq = 1 ...检查答案... – ilansch 2013-03-18 10:40:45