WCF-Service über mehrere HTTP-Bindings ansprechen

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

enjoyed the post?

Tags:

Comments are closed

About Oliver

shades-of-orange.com code blog logo I build web applications using ASP.NET and have a passion for javascript. Enjoy MVC 4 and Orchard CMS, and I do TDD whenever I can. I like clean code. Love to spend time with my wife and our children. My profile on Stack Exchange, a network of free, community-driven Q&A sites

About Anton

shades-of-orange.com code blog logo I'm a software developer at teamaton. I code in C# and work with MVC, Orchard, SpecFlow, Coypu and NHibernate. I enjoy beach volleyball, board games and Coke.