Work with Azure with a Crazy URL

I deploy webrole in azure, which contains the website and the wcf service ...
The site uses services from wcf.
The problem here is that middle tier deployment creates a crazy url for the endpoints, and I have to keep changing the endpoints in the web.config file ...

I am wondering if theres a way to "predict" what the URL will be or make it point or point to a shared host, such as "localhost" ???

+5
source share
2 answers

You can use role detection to find the WCF endpoint. See this answer here and the blog post it refers to.

. :

    #region Channel
    protected String roleName;
    protected String serviceName;
    protected String endpointName;
    protected String protocol = @"http";

    protected EndpointAddress _endpointAddress;
    protected BasicHttpBinding httpBinding;
    protected NetTcpBinding tcpBinding;

    protected IChannelFactory channelFactory;
    protected T client;

    protected virtual AddressHeader[] addressHeaders
    {
        get
        {
            return null;
        }
    }

    protected virtual EndpointAddress endpointAddress
    {
        get
        {
            if (_endpointAddress == null)
            {
                var endpoints = RoleEnvironment.Roles[roleName].Instances.Select(i => i.InstanceEndpoints[endpointName]).ToArray();
                var endpointIP = endpoints.FirstOrDefault().IPEndpoint;
                if(addressHeaders != null)
                {
                    _endpointAddress = new EndpointAddress(new Uri(String.Format("{1}://{0}/{2}", endpointIP, protocol, serviceName)), addressHeaders);
                }
                else
                {
                    _endpointAddress = new EndpointAddress(String.Format("{1}://{0}/{2}", endpointIP, protocol, serviceName));
                }

            }
            return _endpointAddress;
        }
    }

    protected virtual Binding binding
    {
        get
        {
            switch (protocol)
            {
                case "tcp.ip":
                    if (tcpBinding == null) tcpBinding = new NetTcpBinding();
                    return tcpBinding;
                default:
                    //http
                    if (httpBinding == null) httpBinding = new BasicHttpBinding();
                    return httpBinding;
            }
        }
    }

    public virtual T Client
    {
        get
        {
            if (this.client == null)
            {
                this.channelFactory = new ChannelFactory<T>(binding, endpointAddress);
                this.client = ((ChannelFactory<T>)channelFactory).CreateChannel();
                ((IContextChannel)client).OperationTimeout = TimeSpan.FromMinutes(2);
                var scope = new OperationContextScope(((IContextChannel)client));
                addCustomMessageHeaders(scope);
            }
            return this.client; 
        }
    }
    #endregion

():

this.roleName = "WebServiceRole";
this.endpointName = "HttpInternal";
this.serviceName = "services/Accounts.svc";

( ) URL-.

. : WCF

+1

GUID, - .

, - URL- .CSCFG URL- WCF Azure

0

All Articles