by Oliver
25. May 2010 16:55
Neulich habe ich für www.camping.info einen Webservice gebaut, der per Javascript unter allen Subdomains funktionieren sollte. Leider gibt es Probleme, wenn ich unter en.camping.info per Javascript auf www.camping.info/service.svc zugreifen will (wohl wegen cross-domain request).
Es blieb also nur die Möglichkeit, den WCF-Service unter allen Subdomains bereitzustellen. Die Lösung sieht so aus:
1: <system.serviceModel>
2: <behaviors>
3: <endpointBehaviors>
4: <behavior name="webHttpBhv">
5: <webHttp/>
6: </behavior>
7: </endpointBehaviors>
8: <serviceBehaviors>
9: <behavior name="httpGetBhv">
10: <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
11: <serviceMetadata httpGetEnabled="true"/>
12: <!-- 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 -->
13: <serviceDebug includeExceptionDetailInFaults="true"/>
14: </behavior>
15: </serviceBehaviors>
16: </behaviors>
17: <serviceHostingEnvironment aspNetCompatibilityEnabled="true">
18: <baseAddressPrefixFilters>
19: <add prefix="http://www.camp.info"/>
20: </baseAddressPrefixFilters>
21: </serviceHostingEnvironment>
22: <services >
23: <service name="Generic.Frontend.Web.Ajax" behaviorConfiguration="httpGetBhv">
24: <endpoint address="http://bg.camp.info/ajax.svc/" binding="webHttpBinding" behaviorConfiguration="webHttpBhv" contract="Generic.Frontend.Web.Ajax" />
25: <endpoint address="http://bs.camp.info/ajax.svc/" binding="webHttpBinding" behaviorConfiguration="webHttpBhv" contract="Generic.Frontend.Web.Ajax" />
26: ...
27: <endpoint address="http://www.camp.info/ajax.svc/" binding="webHttpBinding" behaviorConfiguration="webHttpBhv" contract="Generic.Frontend.Web.Ajax" />
28: <endpoint address="http://partner.camp.info/ajax.svc/" binding="webHttpBinding" behaviorConfiguration="webHttpBhv" contract="Generic.Frontend.Web.Ajax" />
29: <endpoint address="http://camp.info/ajax.svc/" binding="webHttpBinding" behaviorConfiguration="webHttpBhv" contract="Generic.Frontend.Web.Ajax" />
30: </service>
31: </services>
32: </system.serviceModel>
Für jeden Endpoint muss jetzt allerdings im IIS ein Binding vorhanden sein, sonst gibt es (für das fehlende Binding) den folgenden Fehler:
No protocol binding matches the given address 'http://nonexistent.camp.info/ajax.svc/'. Protocol bindings are configured at the Site level in IIS or WAS configuration.
Gruß, Oliver