我想在IIS 7.5中託管WCF 4.0服務,並且能夠使用basicHttpBinding
綁定到WCF 4.0服務,還可以使用webHttpBinding
以REST方式綁定它。WCF服務上的多個綁定
我需要能夠訪問它,像這樣:
http://server/wcf/service/method/parameters(REST)
,也像這樣:
http://server/wcf/service.svc(基本HTTP)
到目前爲止,我有這對於我的Web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="json">
<webHttp defaultOutgoingResponseFormat="Json" helpEnabled="true" />
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="SAIF.Services.WCF.Services.CustomerContactService">
<endpoint address="CustomerContact" behaviorConfiguration="json" binding="webHttpBinding" contract="SAIF.Services.WCF.Contracts.ICustomerContactService" />
<endpoint address="CustomerContact.svc" binding="basicHttpBinding" contract="SAIF.Services.WCF.Contracts.ICustomerContactService" />
</service>
<service name="SAIF.Services.WCF.Services.OnlineLoginService">
<endpoint address="OnlineLogin" binding="basicHttpBinding" contract="SAIF.Services.WCF.Contracts.IOnlineLoginService" />
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
<serviceActivations>
<add relativeAddress="CustomerContact.svc" service="SAIF.Services.WCF.Services.CustomerContactService" />
</serviceActivations>
</serviceHostingEnvironment>
</system.serviceModel>
</configuration>
我也有這個在激活的擴展少我的Global.asax文件:
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application is started
Routing.RouteTable.Routes.Add(New ServiceRoute("CustomerContact", New ServiceHostFactory, GetType(SAIF.Services.WCF.Services.CustomerContactService)))
Routing.RouteTable.Routes.Add(New ServiceRoute("OnlineLogin", New ServiceHostFactory, GetType(SAIF.Services.WCF.Services.OnlineLoginService)))
End Sub
我已經裝飾服務與此:
我的服務接口的與UriTemplates
別t似乎能夠通過SOAP以REST方式和SOAP訪問它們。
謝謝! Sam
爲什麼它必須是相同的基本URL?爲什麼不'http:// server/wcf/restservice/method/parameters'和'http:// server/wcf/soapservice/service.svc'? –
@JohnSaunders - 我們將擁有20-25個WCF服務,所以我在考慮這個命名約定,以便於維護,但我想它可能有點不同。 – Sam
我的建議將允許「soapservice」和「restservice」在IIS中成爲獨立的應用程序。 「restservice」將成爲映射到路由的平穩URL的開始。 –