Can I access ServiceEndpoint in Azure WCF Service Web Role?
I used to override CreateServiceHost for my regular WCF Service and modify the endpoin开发者_JAVA百科t there (adding some method dynamically). Now moving to Azure, and having WCF Service Web Role, the myServiceHost.Description.Endpoints is empty (which I guess is normal, as the whole thing works OK). But how could I modify the endpoint, if there's not one available?
Andres
// I can access this in Azure WCF Service Web Role
RoleInstanceEndpoint azureEndpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Endpoint1"];
// but I need something like this (to modify it, as I used to do in plain WCF)
ServiceEndpoint usualEndpoint = myServiceHost.Description.Endpoints[0];
PS I can modify it after opening:
myServiceHost.Opened += AfterOpened;
and then
public static void AfterOpened(object sender, EventArgs e)
{
ServiceHost myServiceHost = sender as ServiceHost;
ServiceEndpoint usualEndpoint = sh.Description.Endpoints[0];
but this way the calling the dynamically generated method would end up with an error like: "The message with Action 'http://tempuri.org/ITestWCFService/Ping' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None)."
OK, the solution is to define endpoint explicitly in Web.config, so we can catch it early enogh, see details here
精彩评论