I modified the configuration and my host code like below.
var ip = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Endpoint1"].IPEndpoint;
var address = new Uri(string.Format("http://{0}/{1}", ip, typeof(EchoService).Name));
_host = new ServiceHost(typeof(EchoService), address);
_host.Opened += (sender, e) =>
{
Trace.WriteLine(string.Format("[INF] Opened at {0}", _host.Description.Endpoints[0].Address));
};
_host.Open();
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding hostNameComparisonMode="Exact">
<security mode="None" />
</binding>
</wsHttpBinding>
<basicHttpBinding>
<binding hostNameComparisonMode="Exact"/>
</basicHttpBinding>
</bindings>
<services>
<service name="WorkerRole1.EchoService">
<endpoint address=""
binding="wsHttpBinding"
contract="WorkerRole1.IEchoService" />
</service>
</services>
</system.serviceModel>
</configuration>
And I also added an attribute on my service class (ref this blog http://itechthoughts.wordpress.com/2009/03/23/hosting-wcf-service-in-windows-azure/)
[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
public class EchoService : IEchoService
{
#region IEchoService Members
public string Echo(string message)
{
var result = string.Format("{0} - {1}", message, DateTime.Now.ToString());
Trace.WriteLine(string.Format("[SVC] {0}", result));
return result;
}
#endregion
}
It works well in the local development fabric (I can use http://localhost:8008/EchoService)
But after I deployed to azure and visit http://mysvc.cloudapp.net:8008/EchoService I got a HTTP 405 error which said "This error (HTTP 405 Method Not Allowed) means that Internet Explorer was able to connect to the website, but the site has a programming
error."
From this post http://social.msdn.microsoft.com/Forums/en-US/windowsazuremanagement/thread/048ecbe9-c68d-4d22-b73f-8b76c060f204/ Mog
said "Besides, Workerrole cannot host http transport wcf, it can only host tcp transport wcf currently."
I don't know if it's impossible to host a HTTP-based (basicHttp or wsHttp) WCF service from a worker role.