lunes, marzo 15, 2010

Config WCF with two host headers (english)

Scenario: WCF with .net framework 3.5 Sp1, Windows 2003 SP2, IIS 6.0 with two host headers.

In this, my first post in english, I write about the configuration details when we need install a WCF service hosting in IIS 6.0 when the Information Server have two or more host header configurated.

Suppose a simplified version of classic WCF sample:

IService1.cs

namespace WCFTest

{

[ServiceContract]

public interface IService1

{

[OperationContract]

string GetData(int value);

}
}

Service1.cs

namespace WCFTest

{

public class Service1 : IService1

{

public string GetData(int value)

{

return string.Format("You entered: {0}", value);

}

}

System.ServiceModel Web.config section:

In this case we use windows authetication, but this issue is not mandatory.

<system.serviceModel>

.....
<bindings>

<basicHttpBinding>

<binding name="BasicHttpBinding_IService1">

<security mode="TransportCredentialOnly">

<transport clientCredentialType="Windows" />

</security>

</binding>

</basicHttpBinding>

</bindings>

<services>

<service behaviorConfiguration="WCFTest.ServiceBehavior" name="WCFTest.Service1">

<endpoint address="" binding="basicHttpBinding" contract="WCFTest.IService1">

<identity>

<dns value="localhost" />

</identity>

</endpoint>

<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

</service>

</services>

<behaviors>

<serviceBehaviors>

<behavior name="WCFTest.ServiceBehavior">

<serviceMetadata httpGetEnabled="true" />

<serviceDebug includeExceptionDetailInFaults="true" />

</behavior>

</serviceBehaviors>

</behaviors>

.....

</system.serviceModel>



The error that ocurrs when the IIS 6.0 has configurated two or more host header is the folowing

Could not find a base address that matches scheme http for the endpoint with binding BasicHttpBinding. Registered base address schemes are [].

This error ocurrs because the WCF runtime cannot know the host header where the service was implemented. In this case we must be configurate in explicit form what is the the IP of the host header when the service should run.

First , we add other System.ServiceModel section

<system.serviceModel>

.....
<serviceHostingEnvironment>

<baseAddressPrefixFilters>

<add prefix="http://<host header IP>" />

</baseAddressPrefixFilters>

</serviceHostingEnvironment>


The sevice and behaviors sections change too.

<service behaviorConfiguration="WCFTest.ServiceBehavior" name="WCFTest.Service1">

<endpoint address=http://<host header IP>/WCFTest/Service1.svc

binding="basicHttpBinding"

contract="WCFTest.IService1">

</endpoint>

<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

</service>


<behaviors>

<serviceBehaviors>

<behavior name="WCFTest.ServiceBehavior">

<serviceMetadata httpGetEnabled="true"
httpGetUrl="http://<host header IP>/CASServices/Services.svc/>

<serviceDebug includeExceptionDetailInFaults="true" />

</behavior>

</serviceBehaviors>

</behaviors>

.....

</system.serviceModel>


Note: In the production environment is recomended the set in false the httpGetEnabled and includeExceptionDetailInFaults attributes.

1 comentario:

Anónimo dijo...
Este blog ha sido eliminado por un administrador de blog.