wcf 同时支持webhttp 和 引用方式

时间:2023-03-09 02:34:57
wcf  同时支持webhttp 和 引用方式

wcf 实现参考

http://www.cnblogs.com/mingmingruyuedlut/p/4223116.html

兼容两种方式

1、修改服务端webconfig

<system.serviceModel>

    <services>
<service name="xxx" behaviorConfiguration="Default">
<endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" bindingConfiguration="basicTransport" contract="Ixxx"/>/*提供WebGet服务用*/
<endpoint address="Wcf" binding="basicHttpBinding" contract="Ixxx"/>/*提供WCF服务 , 注意address='Wcf',为了区分开与WebGet的地址,添加引用之后会自动加上的 */
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex"/>/*元数据endpoint*/
</service>
</services> <behaviors>
<serviceBehaviors>
<behavior name="Default">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors> <endpointBehaviors>
<behavior name="web">
<webHttp helpEnabled="true"/>
</behavior>
</endpointBehaviors>
</behaviors> <bindings>
<webHttpBinding>
<binding name="basicTransport"/>
</webHttpBinding>
</bindings> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> </system.serviceModel>

Web调用地址:http://ip:port/xxx.svc/yyy/id

  Wcf服务地址会变为:http://ip:port/xxx.svc/Wcf