1.首先新建一个wcf的project
选择新建wcf项目。
2.在IService接口中定义并配置方法
[ServiceContract]
public interface IDataService
{
[OperationContract]
[WebGet(UriTemplate = "Metrics?page={page}&pagesize={pagesize}",
ResponseFormat = WebMessageFormat.Json)]
[Description("Returns a list of all Metrics.")]
ICollection<MetricNodes> GetAllMetrics(int page, int pagesize);
[OperationContract]
[WebGet(UriTemplate = "Nodes?userName={userName}&userDomain={userDomain}", ResponseFormat = WebMessageFormat.Json)]
[Description("Returns a list of all MetricNodes.")]
ICollection<MetricNodes> GetRootMetricNodes(string userName, string userDomain);
3在Svc文件中配置
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class EmiteDataService : IEmiteDataService
{
public ICollection<MetricNodes> GetAllMetrics(int page, int pagesize)
{
........}
}
<system.serviceModel>
<services>
<service behaviorConfiguration="CfxixiDataServiceBehavior" name="CfxixiDataService.EmiteDataService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:6340/CfxixiDataService/"/>
</baseAddresses>
</host>
<endpoint address="" binding="webHttpBinding" contract="CfxixiDataService.Service.IEmiteDataService" behaviorConfiguration="webBehavior" bindingConfiguration="webBinding"></endpoint>
<!--<endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttp" contract="EmiteDataService.Service.IEmiteDataService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>-->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="basicHttp" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" closeTimeout="00:10:00" openTimeout="00:10:00" sendTimeout="00:10:00" receiveTimeout="00:10:00">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
</binding>
<binding name="BasicTransportSecurity">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
<webHttpBinding>
<binding name="webBinding" crossDomainScriptAccessEnabled="true"></binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="CfxixiDataServiceBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
如此便大功告成,发布访问svc文件即可。