1
votes

I've created a WCF service and hosted it in cloud through a worker role. Unfortunately when I try to connect to the worker role service I get an exception with the message: "No DNS entries exist for host 3a5c0cdffcf04d069dbced5e590bca70.cloudapp.net." 3a5c0cdffcf04d069dbced5e590bca70.cloudapp.net is the address for the worker role deployed in azure staging environment. The workerrole.cs has the following code to expose the WCF service:

    public override void Run()
    {
        using (ServiceHost host = new ServiceHost(typeof(MyService)))
        {
            string ip = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["tcppoint"].IPEndpoint.Address.ToString();
            int tcpport = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["tcppoint"].IPEndpoint.Port;
            int mexport = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["mexinput"].IPEndpoint.Port;

            // Add a metadatabehavior for client proxy generation
            // The metadata is exposed via net.tcp
            ServiceMetadataBehavior metadatabehavior = new ServiceMetadataBehavior();
            host.Description.Behaviors.Add(metadatabehavior);
            Binding mexBinding = MetadataExchangeBindings.CreateMexTcpBinding();
            string mexlistenurl = string.Format("net.tcp://{0}:{1}/MyServiceMetaDataEndpoint", ip, mexport);
            string mexendpointurl = string.Format("net.tcp://{0}:{1}/MyServiceMetaDataEndpoint", RoleEnvironment.GetConfigurationSettingValue("Domain"), 8001);
            host.AddServiceEndpoint(typeof(IMetadataExchange), mexBinding, mexendpointurl, new Uri(mexlistenurl));

            // Add the endpoint for MyService
            string listenurl = string.Format("net.tcp://{0}:{1}/MyServiceEndpoint", ip, tcpport);
            string endpointurl = string.Format("net.tcp://{0}:{1}/MyServiceEndpoint", RoleEnvironment.GetConfigurationSettingValue("Domain"), 9001);
            host.AddServiceEndpoint(typeof(IMyService), new NetTcpBinding(SecurityMode.None), endpointurl, new Uri(listenurl));
            host.Open();

            while (true)
            {
                Thread.Sleep(100000);
                Trace.WriteLine("Working", "Information");
            }
        }
    } 

The tcppoint and mexinput are configured with the ports 8001 and 9001. Also Domain is configured with worker role deployment url:3a5c0cdffcf04d069dbced5e590bca70.cloudapp.net

On the client part(a console app), we are using the following configuration in app.config::

    <bindings>
        <netTcpBinding>
            <binding name="NetTcpBinding_IMyService" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
                hostNameComparisonMode="StrongWildcard" listenBacklog="10"
                maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
                maxReceivedMessageSize="65536">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="00:50:00"
                    enabled="false" />
                <security mode="None">
                    <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                    <message clientCredentialType="Windows" />
                </security>
            </binding>
        </netTcpBinding>

    </bindings>
    <client>
      <endpoint address="httpp:\\3a5c0cdffcf04d069dbced5e590bca70.cloudapp.net:9001/MyServiceEndpoint" binding="netTcpBinding"
         bindingConfiguration="NetTcpBinding_IMyService" contract="ServiceReference1.IMyService"
         name="NetTcpBinding_IMyService" />
    </client>

  <behaviors>
    <serviceBehaviors>
      <behavior name="behave">
        <serviceMetadata httpGetEnabled="false"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>   

</system.serviceModel>
<system.net>
  <defaultProxy useDefaultCredentials="true">
  <proxy autoDetect="False" usesystemdefault="False" bypassonlocal="True" />
</defaultProxy>

The following code is built using the sample code available in msdn as background. Locally it is working fine. Unfortunately when i deploy it to cloud, the exception occurs. Moreover, when i use the virtual ip instead of the url, a connection time out occurs with the exception the remote machine did not respond.

2
What does your ServiceDefinition.csdef say? Does it expose external endpoint on port 9001 for the role? It would help if you paste the content of ServiceDefinition.csdef into your question.seva titov
The service definition code is given below:: <WorkerRole name="WorkerRole1"> <Endpoints> <InputEndpoint name="tcppoint" protocol="tcp" port="9001" /> <InputEndpoint name="mexinput" protocol="tcp" port="8001" /> </Endpoints> <ConfigurationSettings> <Setting name="Domain" /> </ConfigurationSettings> </WorkerRole>rohit shome

2 Answers

0
votes

Looks like you have your service setup to listen on net.tcp (TCP) and your client using http bindings. I would not expect that to work even locally. I am assuming you have actually opened port 9000 in the ServiceDefinition. Remember that will be a load-balanced endpoint. Are you trying to communicate to this instance from within the deployment (inter-role) or from outside the cloud?

I have found it is a lot easier to setup the host and client (when communicating within a role) through code. Try this:

http://dunnry.com/blog/2010/05/28/HostingWCFInWindowsAzure.aspx

If you are trying to hit the service from a client outside the deployment, this still applies, but for the client building part. You will need to use the external DNS name and port defined in ServiceDefinition.

I have also seen DNS errors if you try to hit the endpoint too soon before the role was ready. It can take a bit to propogate the DNS and you should try not to resolve it until it is ready, lest you cache a bogus DNS entry. If you can resolve that DNS name however to your VIP address, that is not the issue.

-2
votes
    public void CallWebService(string data)
    {

        try
        {
            string uri = "url"+data;

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            Stream str = response.GetResponseStream();

            StreamReader sr = new StreamReader(str);

            String IResponse = sr.ReadToEnd();


        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Message: "+ex.Message);
        }

    }

Hope it helps you.