看著別人把WCF服務和web請求結合一起用很爽,可是自己怎麼也配置不出來(沒有用web host),所以研究了一下wcf的binding的配置
- endpoint的 binding必須為webHttpBinding.
- Endpoint的behavior中要加入webhttp.
樣本設定檔如下:
<?xml
version="1.0"
encoding="utf-8" ?>
<configuration>
<system.web>
<compilation
debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service
name="Services.PlayerService"
behaviorConfiguration="bh">
<host>
<baseAddresses>
<add
baseAddress = "http://localhost:8731/PlayerService/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint
address =""
binding="basicHttpBinding"
contract="Contrat.IPlayerService"
behaviorConfiguration="web"></endpoint>
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior
name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior
name="bh">
<!-- 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="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>