在网上找到的一个例子。共分 Service1 Client Host 三部分
Service1启动运行正常,
Client在Service启动时运行也正常,
Host启动时报错【服务“IService1.Service1”有零个应用程序(非基础结构)终结点】代码:
HOST
namespace WindowsForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
ServiceHost host = null; private void button1_Click(object sender, EventArgs e)
{
host =new ServiceHost(typeof(IService1.Service1));
host.Open();
this.label1.Text = "服务已启动";
} private void button2_Click(object sender, EventArgs e)
{
if (host.State != CommunicationState.Closed)
{
host.Close();
}
this.label1.Text = "服务以关闭";
} }
}web.config
<system.serviceModel>
<services>
<service name="IService1.Service1" behaviorConfiguration="CalculatorServiceBehavior">
<host>
<baseAddresses>
add baseAddress="http://localhost:8642/"/>
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" contract="IService1.IService1"></endpoint>
</service>
</services> <behaviors>
<serviceBehaviors>
<behavior name="CalculatorServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Service1启动运行正常,
Client在Service启动时运行也正常,
Host启动时报错【服务“IService1.Service1”有零个应用程序(非基础结构)终结点】代码:
HOST
namespace WindowsForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
ServiceHost host = null; private void button1_Click(object sender, EventArgs e)
{
host =new ServiceHost(typeof(IService1.Service1));
host.Open();
this.label1.Text = "服务已启动";
} private void button2_Click(object sender, EventArgs e)
{
if (host.State != CommunicationState.Closed)
{
host.Close();
}
this.label1.Text = "服务以关闭";
} }
}web.config
<system.serviceModel>
<services>
<service name="IService1.Service1" behaviorConfiguration="CalculatorServiceBehavior">
<host>
<baseAddresses>
add baseAddress="http://localhost:8642/"/>
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" contract="IService1.IService1"></endpoint>
</service>
</services> <behaviors>
<serviceBehaviors>
<behavior name="CalculatorServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
解决方案 »
- 求助怎样用c#创建sql表的时候以textbox中输入的内容给所要创建的表命名
- 看不懂这段代码。望指点
- C#绘制欧姆表类似于手表盘的图形,怎么设计啊?急急急
- 请问我若有N张BMP小图片,想要放到PictureBox 然后保存成一张BMP
- Cannot close stream until all bytes are written错误怎么处理。
- sql语句的问题!!
- 在datagrid中如何加入RadioButtonList控件,并且能够写到数据库中
- 请教如何实现这样的控件?
- 怎么设计一个像window MediaPlayer一样的界面?
- 不同cs文件中,如何引用自定义的Class
- vs2010 rdlc 报表问题?
- 如何修改代码,解决checkBox与textbox同时入库同1条ID的问题
namespace IService1
{
// 注意: 如果更改此处的类名“Service1”,也必须更新 Web.config 和关联的 .svc 文件中对“Service1”的引用。
public class Service1 : IService1 //服务 文件名为 Service1.svc
{
Ticket T = new Ticket(); public void AddTicket(int count)
{
T.HowMany = T.HowMany + count;
} public int GetRemainingNum()
{
return T.HowMany;
}
.......................剩余代码//服务继承的接口
namespace IService1
{
// 注意: 如果更改此处的接口名称 "IService1",也必须更新 Web.config 中对 "IService1" 的引用。
[ServiceContract]
public interface IService1
{ [OperationContract]
string GetData(int value);
................剩余代码
发布之后的目录可能和本机测试不同。
使用fiddler进行抓包
检查webconfig