Serviece.cs
------------------------------------------------------------------------------------------
using System;
using System.Configuration;
using System.ServiceModel;
namespace WCFTEST
{
[ServiceContract(Namespace = "http://WCFTEST.Service")]
public interface ICustomerService
{
[OperationContract]
String CustomerInformation();
}
public class CustomerService : ICustomerService
{
#region ICustomerService 成员
public string CustomerInformation()
{
return "这是客户的信息!";
}
#endregion
}
public class Host
{
public static void Main()
{
using (ServiceHost host = new ServiceHost(typeof(CustomerService)))
{
try
{
host.Open();
Console.WriteLine("客户信息服务已启动");
Console.WriteLine("按任意键结束服务!");
Console.Read();
host.Close();
}
catch (TimeoutException ex)
{
Console.WriteLine(ex.Message);
Console.Read();
}
catch (CommunicationException ex)
{
Console.WriteLine(ex.Message);
Console.Read();
}
}
}
}
}
App.Config
--------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service
name="WCFTEST.CustomerService"
behaviorConfiguration="CalculatorServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/WCFTEST"/>
</baseAddresses>
</host>
<!-- This endpoint is exposed at the base address provided by http://localhost:8000/ServiceModelSamples/service -->
<endpoint address=""
binding="wsHttpBinding"
contract="WCFTEST.ICustomerService" />
</service>
</services>
<!--For debugging purposes, set the includeExceptionDetailInFaults attribute to true.-->
<behaviors>
<serviceBehaviors>
<behavior name="CalculatorServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
本文介绍了一个使用 WCF 实现的简单客户信息服务示例。该服务提供了一个名为 CustomerInformation 的操作契约,用于返回预设的客户信息。通过 wsHttpBinding 绑定和指定的地址暴露服务。
2069

被折叠的 条评论
为什么被折叠?



