<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="conn" connectionString="server=.;database=Users;uid=sa;pwd=123456;" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点 -->
<serviceMetadata httpGetEnabled="true"/>
<!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 -->
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" >
<baseAddressPrefixFilters>
<add prefix="string"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
<services>
<service name="IUserTest" >
<endpoint address="" behaviorConfiguration="webBehavior"
binding="webHttpBinding" contract="IUserTest" />
<!--<endpoint address="" binding="basicHttpBinding" contract="ReaderService" />-->
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="webBinding" crossDomainScriptAccessEnabled="true"></binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
注:1.在svc的文件中<%@ ServiceHost Language="C#" Debug="true" Service="WCFTest.UserTest" CodeBehind="UserTest.svc.cs" Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>
要加上Factory="System.ServiceModel.Activation.WebServiceHostFactory"
2.在代码上加上 [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
3.在接口上加上 [WebInvoke(ResponseFormat = WebMessageFormat.Json,UriTemplate="/方法名", Method="GET" ,BodyStyle = WebMessageBodyStyle.Wrapped)]