locked
Cannot consume WCF service net.tcp protocol in Silverlight RRS feed

  • Question

  • Hi all,

    I am running to the trouble of consuming WCF net.tcp in silverlight. I have a project which create and host WCF to Windows Azure using net.tcp protocol. Now I want to consume this service with Silverlight client. However, I could not make it work.

    In my project, I create a web role in Windows Azure which will host WCF net.tcp protocol. In client site, I create Silverlight project using this service. When I make a call from Silverlight to this service (hosted in Windows Azure), I always get the error TCP error code 10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. This could be due to attempting to access a service in a cross-domain way while the service is not configured for cross-domain access.

    In the service config file, here is the configuration:

    <bindings>
          <netTcpBinding>
            <binding name="tcpBinding">
              <security mode="None"/>
            </binding>
          </netTcpBinding>
    </bindings>
    <services>
          <service name="Service1">
            <endpoint address="net.tcp://testnettcp.cloudapp.net:4503/WebRole1/Service1.svc"
                      binding="netTcpBinding" bindingConfiguration="tcpBinding"
                      contract="WebRole1.IService1"/>
            <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
          </service>
    </services>

    In the silverlight client site, here is the configuration:

    <bindings>
          <customBinding>
            <binding name="TcpBinding">
              <binaryMessageEncoding />
              <tcpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"/>
            </binding>
          </customBinding>
     </bindings>
     <client>

                  <endpoint address="net.tcp://testnettcp.cloudapp.net:4503/Service/Service1.svc"
                   binding="customBinding" bindingConfiguration="TcpBinding"
                   contract="Service1.IService1" name="NetTcpBinding_Service1"/>
     </client>

    In the OnStart() method of WebRole in Windows Azure, I also have a script to configure IIS of Windows Azure:

    public override bool OnStart()
            {
                var startInfo = new ProcessStartInfo()
                {
                    FileName = "powershell.exe",
                    Arguments = @".\setup\rolestart.ps1",
                    RedirectStandardOutput = true,
                    UseShellExecute = false,
                };

                var writer = new StreamWriter("out.txt");

                var process = Process.Start(startInfo);
                process.WaitForExit();
                writer.Write(process.StandardOutput.ReadToEnd());
                writer.Close();

                return base.OnStart();
            }

    where rolestart.ps1 is a PowerShell script as follow:

    write-host "Begin RoleStart.ps1"
    import-module WebAdministration

    # Starting the listener service
    $listenerService = Get-WmiObject win32_service -filter "name='NetTcpActivator'"
    $listenerService.ChangeStartMode("Manual")
    $listenerService.StartService()
    $listenerService = Get-WmiObject win32_service -filter "name='NetTcpPortSharing'"
    $listenerService.ChangeStartMode("Manual")
    $listenerService.StartService()

    # Enable net.pipe bindings
    $WebRoleSite = (Get-WebSite "*webrole*").Name
    Get-WebApplication -Site $WebRoleSite | Foreach-Object { $site = "IIS:/Sites/$WebRoleSite" + $_.path; Set-ItemProperty $site -Name EnabledProtocols 'http,net.tcp'}
    New-ItemProperty "IIS:/Sites/$WebRoleSite" -name bindings -value @{protocol="net.tcp";bindingInformation="808:*"}

    write-host "End RoleStart.ps1"


    These above steps I got from this site: http://blogs.msdn.com/b/windowsazure/archive/2011/06/27/hosting-services-with-was-and-iis-on-windows-azure.aspx


    Is there anyone can help take a look and advise me solving this issue?



    Thanks,

    Tuesday, July 12, 2011 2:59 AM

Answers