wcf第2步之服务端标准配置文件

服务端app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="WCFTest.GreetService" behaviorConfiguration="GreetServiceBehavior">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:20000/" />
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" contract="WCFTest.IGreetService" >

</endpoint>
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="GreetServiceBehavior">
<!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点-->
<serviceMetadata httpGetEnabled="true"/>
<!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息-->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

 

class Program
{
static void Main(string[] args)
{
ServiceHost host = new ServiceHost(typeof(GreetService)); 
host.Open();
Console.WriteLine("服务已开启");
Console.Read();
}
}

[ServiceContract]
public interface IGreetService
{
[OperationContract]
string Greet(string name);

}

public class GreetService : IGreetService
{

public string Greet(string name)
{
Console.WriteLine(("Hello:"+name));
return "Welcome:" + name;
}
}

 

posted @ 2016-06-17 16:59  zslm___  阅读(194)  评论(0编辑  收藏  举报