我自己做 了一个demo,用wcf进行通信,但是客户端代理老是生成不了,宿主用的是 windows服务,在安装windows 服务的时候老是出错,不知道哪的问题 下面是代码:namespace WcfTest
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract(Namespace = "www.huhang360.com/")]
public interface IService1
{
[OperationContract]
string GetNameString(string Name);
}这个是wcf里的代码 namespace WcfTest
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
public class Service1 : IService1
{
User user = new User();
public string GetNameString(string Name)
{
//System.Diagnostics.Debugger.Break();// 去掉注释即可调试服务
return user.GetName(Name );
} }
}
下边是windows服务里 的代码:using WcfTest;namespace WindowsServiceTest
{
public partial class ServiceHostController : ServiceBase
{
private static ServiceHost ServiceControl=null ;
public ServiceHostController()
{
InitializeComponent();
// this.ServiceName = "自定义服务1";
}
protected override void OnStart(string[] args)
{
if ( ServiceControl !=null )
{
ServiceControl.Close();
}
ServiceControl = new ServiceHost(typeof(Service1));
ServiceControl.Open();
} protected override void OnStop()
{
}
}
}
最下边是app.config中的配置
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="WcfTest.ServiceTest"
behaviorConfiguration="WcfTest.WcfTestServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:9000/Services"/>
</baseAddresses>
</host>
<endpoint address="net.tcp://localhost:9000/Services" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IService1" contract="WcfTest.IService1">
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_IService1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:01:00" sendTimeout="00:01:00"
maxReceivedMessageSize="2147483647"
>
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="WcfTest.WcfTestServiceBehavior">
<serviceMetadata httpGetEnabled="false" httpGetUrl ="http://localhost:8080/Services/ServiceTest"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
现在安装的时候都出错 求高手赐教 我的配置文件有错误吗?
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract(Namespace = "www.huhang360.com/")]
public interface IService1
{
[OperationContract]
string GetNameString(string Name);
}这个是wcf里的代码 namespace WcfTest
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
public class Service1 : IService1
{
User user = new User();
public string GetNameString(string Name)
{
//System.Diagnostics.Debugger.Break();// 去掉注释即可调试服务
return user.GetName(Name );
} }
}
下边是windows服务里 的代码:using WcfTest;namespace WindowsServiceTest
{
public partial class ServiceHostController : ServiceBase
{
private static ServiceHost ServiceControl=null ;
public ServiceHostController()
{
InitializeComponent();
// this.ServiceName = "自定义服务1";
}
protected override void OnStart(string[] args)
{
if ( ServiceControl !=null )
{
ServiceControl.Close();
}
ServiceControl = new ServiceHost(typeof(Service1));
ServiceControl.Open();
} protected override void OnStop()
{
}
}
}
最下边是app.config中的配置
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="WcfTest.ServiceTest"
behaviorConfiguration="WcfTest.WcfTestServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:9000/Services"/>
</baseAddresses>
</host>
<endpoint address="net.tcp://localhost:9000/Services" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IService1" contract="WcfTest.IService1">
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_IService1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:01:00" sendTimeout="00:01:00"
maxReceivedMessageSize="2147483647"
>
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="WcfTest.WcfTestServiceBehavior">
<serviceMetadata httpGetEnabled="false" httpGetUrl ="http://localhost:8080/Services/ServiceTest"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
现在安装的时候都出错 求高手赐教 我的配置文件有错误吗?
解决方案 »
- 使用ADO.NET实体框架比直接用ADO.NET字符串连接数据库强在哪里呢?
- WebBrower控件如何实现缩略显示网页
- CheckBoxList 冒名顶替的精髓问题!期待比我高的高手解决
- C#中动态数据交换好象与VB\VC++中的不同了,请各位提示一下,是用哪一个类实现的:)谢谢(第一次发贴)
- 求助! VB代码在C#下如何写
- web项目怎么启动winfrm项目中的窗体(winfrm已编译为dll,已引用)
- 一个关于winform的笨鸟问题!
- 理论问题!!!
- C#如何访问剪切板
- Wpf RichTextBox如何删除最后一行(求助各位大神)
- 关于C#中想SQL存储过程 传参数的问题
- C# 如何继承DLL中的接口,并实现接口的功能。
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:9000/Services"/>
</baseAddresses>
</host>改为
<host>
<baseAddresses>
<add baseAddress="http://localhost:9000/Services"/>
</baseAddresses>
</host>
Service cannot be started. System.InvalidOperationException: Service 'WcfService1.User' 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.