Answered by:
Cannot consume WCF service using net.tcp protocol hosted in Windows Azure in Silverlight

Question
-
Hi all,
I am running to the trouble of consuming WCF using net.tcp protocol in silverlight. I have a project which create and host WCF service 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. I guess that I may not enable tcp port on windows azure, but dont know how.
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"I also have clientaccesspolicy.xml file which placed at the root of the website and I am able to browse to this file. Its content is as follow:
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="*">
<domain uri="*"/>
</allow-from>
<grant-to>
<socket-resource port="4503" protocol="tcp" />
</grant-to>
</policy>
</cross-domain-access>
</access-policy>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 , but I still cannot make it work.
Is there anyone can help take a look and advise me solving this issue?
Thanks,
Nguyen
Tuesday, July 12, 2011 7:06 AM
Answers
-
Hi Nguyen,
As the WCF service is exposed in a new port 4503, I'd like to confirm with you if you have defined an input endpoint (in ServiceDefinition.csdef file) for that port:
<ServiceDefinition name="MyService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
<WorkerRole name="WorkerRole1">
<Endpoints>
<InputEndpoint name="Endpoint2" protocol="tcp" port="4503" localPort="4503" />
</Endpoints>
</WorkerRole>
</ServiceDefinition>Also, when adding site bindings via powershell, as you are using port 4503, the binding information should be "4503:*" instead of "808:*":
New-ItemProperty "IIS:/Sites/$WebRoleSite" -name bindings -value @{protocol="net.tcp";bindingInformation="4503:*"}
To ensure the startup task has started the services and configured IIS properly, I'd suggest you enable RDP for your web role and then open a remote desktop to a service instance to confirm it.
Thanks.
Wenchao Zeng
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code Framework- Proposed as answer by Wenchao Zeng Wednesday, July 20, 2011 6:38 AM
- Marked as answer by Wenchao Zeng Thursday, July 21, 2011 5:36 AM
Wednesday, July 13, 2011 7:00 AM
All replies
-
Hi Nguyen,
I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.
Thanks.
Wenchao Zeng
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code FrameworkWednesday, July 13, 2011 5:55 AM -
Hi Nguyen,
As the WCF service is exposed in a new port 4503, I'd like to confirm with you if you have defined an input endpoint (in ServiceDefinition.csdef file) for that port:
<ServiceDefinition name="MyService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
<WorkerRole name="WorkerRole1">
<Endpoints>
<InputEndpoint name="Endpoint2" protocol="tcp" port="4503" localPort="4503" />
</Endpoints>
</WorkerRole>
</ServiceDefinition>Also, when adding site bindings via powershell, as you are using port 4503, the binding information should be "4503:*" instead of "808:*":
New-ItemProperty "IIS:/Sites/$WebRoleSite" -name bindings -value @{protocol="net.tcp";bindingInformation="4503:*"}
To ensure the startup task has started the services and configured IIS properly, I'd suggest you enable RDP for your web role and then open a remote desktop to a service instance to confirm it.
Thanks.
Wenchao Zeng
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code Framework- Proposed as answer by Wenchao Zeng Wednesday, July 20, 2011 6:38 AM
- Marked as answer by Wenchao Zeng Thursday, July 21, 2011 5:36 AM
Wednesday, July 13, 2011 7:00 AM -
I dont think it is supported now.Friday, July 15, 2011 3:14 PM
-
Hi Zeng,
Thank you so much for your valuable support.
Actually I was trying to deploy WCF net.tcp on Azure using WebRole, but not WorkerRole. I have tried all possible options, checked all configurations even with adding endpoint <InputEndpoint name="Endpoint2" protocol="tcp" port="4503" localPort="4503" /> or modifing script New-ItemProperty "IIS:/Sites/$WebRoleSite" -name bindings -value @{protocol="net.tcp";bindingInformation="4503:*"} but still not luck.
However, there might have troubles with my computer because all my configurations can work on another computer of my colleague. I didn't know it at the beginning and it took me several days getting crazy. I am checking it out and will post my working example to this forum once it is done so that anyone who need it can get the tips.One interesting thing is that I expect the net.tcp protocol will help improve the performance of my application comparing to http protocol; because the net.tcp protocol is promised to bring better performance for application. However, as my testing, I deployed 2 solutions with 2 protocols (http and net.tcp) but http seems give better performance than net.tcp. Do you have any advices on this situation?
Thank you for your support.
Best regards,
Nguyen
Friday, July 15, 2011 3:33 PM -
Hi Nguyen,
> However, there might have troubles with my computer because all my configurations can work on another computer of my colleague.
I'd suggest you firstly try WCF NET.TCP Protocol in Silverlight and ensure it works on your local machine. After the firstly try, then you move the WCF service to an Azure project and define a tcp input endpoint and execute script file to start the necessary services and add a net.tcp binding for the web site.
> However, as my testing, I deployed 2 solutions with 2 protocols (http and net.tcp) but http seems give better performance than net.tcp. Do you have any advices on this situation?
How did you test the performance? You may want to have a read on High Performance WCF Services : netTcpBinding.
After the servcie is deployed on cloud, you may also consider the network latency between the end user and Azure data servers. For example, the network latency is 100 milliseconds, a call via basic http binding cost 0.2 milliseconds, a call via tcp.net binding cost 0.04 milliseconds, then if a SilverLight calls a WCF service via both bindings will cost 100.2 milliseconds and 100.004 milliseconds. Also the network latency is a dynamic thing that may be changing.
Thanks.
Wenchao Zeng
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code Framework- Proposed as answer by Wenchao Zeng Wednesday, July 20, 2011 6:38 AM
- Unproposed as answer by Wenchao Zeng Wednesday, July 20, 2011 6:38 AM
Monday, July 18, 2011 8:52 AM -
Hi,
I will mark the reply as answer. If you find it no help, please feel free to unmark it and follow up.
Thanks.
Wenchao Zeng
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code FrameworkThursday, July 21, 2011 5:36 AM