Socket programming issue in Silverlight - c#

I have a silverlight application that is communicating with a server hosted in cloud. The application works properly when the server is listening on localhost, but when I make it listen on the server port and make my client access the socket, I get the error "Access denied"
Digging deep, I also found the error in ScopeId resolution
Error Code: 10045
e.RemoteEndPoint. Address.ScopeId threw an exception
The attempted operation is not supported for the type of object referenced.
at System.Net.IPAddress.get_ScopeId()
Thank You

"In Silverlight version 4 for a connection request using System.Net.Sockets, an application can choose instead to retrieve the policy file via the HTTP protocol on TCP port 80 instead of the custom TCP protocol on port 943. This allows HTTP servers that are already running HTTP services to authorize socket connections from Silverlight applications without having to deploy a new TCP service on the machine and open a port through a firewall for port 943."
http://msdn.microsoft.com/en-us/library/cc645032(VS.95).aspx

Related

Web API Crashing after deploy on azure

I am new to Azure, I use the Azure free edition as benchmark .
I developed a webapi service that is using Blob and DocumentDb as DAL, and the webapi works perfect on my local machine.
In my azure account I open App service and I deploy the webapi on azure (using publish).
When I try to surf to my site using the url that was given by azure I receive the following crash error :
**An attempt was made to access a socket in a way forbidden by its access permissions 127.0.0.1:8081
Exception Details: System.Net.Sockets.SocketException: An attempt was
made to access a socket in a way forbidden by its access permissions
127.0.0.1:8081**
I checked my project and I didn't find any mention of that port or address!!!
Please help my to understand the source of this problem.
Are you using asp.net or asp.net core. For sure you have 8081 defined in your web.config or project.json and azure does allow process listening on custom port and hence the error
Are you getting some call stack in the exception? That will help identify the code which is trying to go to 8081
App Service platform execution environment is different from local. All Azure Web Apps (as well as Mobile App/Services, WebJobs and Functions) run in a secure environment called a sandbox. We could get more info about Azure Web App from Azure official document. The following is the snippet from the document.
Network endpoint listening
The only way an application can be accessed via the internet is through the already-exposed HTTP (80) and HTTPS (443) TCP ports; applications may not listen on other ports for packets arriving from the internet.
However, applications may create a socket which can listen for connections from within the sandbox. For example, two processes within the same app may communicate with one another via TCP sockets; connection attempts incoming from outside the sandbox, albeit they be on the same machine, will fail. See the next topic for additional detail.
Local Address Requests
Connection attempts to local addresses (e.g. localhost, 127.0.0.1) and the machine's own IP will fail, except if another process in the same sandbox has created a listening socket on the destination port.
Rejected connection attempts, such as the following example which attempts to connect to 127.0.0.1:80, from .NET will result in the following exception:
Exception Details: System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions 127.0.0.1:80

Error while trying to call a wcf service

I'm trying to connect to a WCF service on a server.
I've set up a Site in the IIS on the server and set the Enabled Protocols to http,net.tcp.
Additionally, I configured the Site Bindings like this:
http > Port: 80 > IP Address: *
net.tcp > Binding Information: 808.*
Under Authentication, I've enabled Anonymous Authentication and Windows Authentication.
The services Net.Tcp Listener Adapter and Net.Tcp Port Sharing Service are running too.
When I call the webservice with a browser (via http), everything works and I can list the wsdl etc.
But when trying to connect via tcp, I get the following error:
Error: Cannot obtain Metadata from net.tcp://myserver/MyService.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: net.tcp://myserver/MyService.svc Metadata contains a reference that cannot be resolved: 'net.tcp://myserver/MyService.svc'. Could not connect to net.tcp://myserver/MyService.svc. The connection attempt lasted for a time span of 00:00:21.0010999. 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 10.x.yyy.zz:808. 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 10.x.yyy.zz:808
Are there any other things I have to make sure to be able to connect via tcp?
Thanks in advance
This seems to be a network issue since 10060 means connect timeout.
Check the server firewall and make sure that Windows Communication Foundation Net.TCP Listener Adapter (TCP-In) rule is enabled.
Check the client computer's firewall and add make sure an outbound rule allowing tcp connections on port 808
If you still can't connect, a network firewall device might be blocking the request
I think that you may need to turn metadata exchange on:
The following explains one way to do it.

SOAP Service "A socket operation was attempted to an unreachable host"

I'm using C# WinForms app to receive data from the remote SOAP service and it's working great on every testing machine with VPN connected/disconnected.
But there is an exception on one PC after connecting it to VPN network:
System.Net.WebException: Unable to connect to the remote server --->
System.Net.Sockets.SocketException: A socket operation was attempted
to an unreachable host XX.XX.XX.XX:443
If it's not connected to VPN its receiving data from the service as intended.
What's wrong there? I've tried to disable AVG and firewall but no success.
Is there port blocked after VPN connected or maybe VPN using the same port?... I really don't know what to do :)
netstat doesn't show 433 port in use, btw
I guess this is port issue but who knows...

firewalls block client of wshttpbinding service

I have a server pc with Windows Server 2008.and i also have a wcf service that work with Port 8525 and host it with Windows Service.i open the port in server firewall (Added Rule).
My server machine has a Valid IP. so my client try to connect to my service at
((http)://MyServerIP:8525/ServiceName).
all of my application users are people that work in companies.so user internet come from a secure network (Proxy Server Or VPN Connection).
the problem is here :
lots of my clients have the connection problem that seems local network block my program connection (if they try to connect to my server system.diagnostics listener will log it) but service does not save any log.
i think their internet Server has Firewall and it block me.i fixed some of them with
<defaultProxy enabled="true" useDefaultCredentials="true" />
but still lots of them have same problem.and the another annoying problem is the network administrators do not open that port because of security issue and do not help me.
A Common Exception is :
System.ServiceModel.EndpointNotFoundException > System.Net.WebException > System.Net.Sockets.SocketException (on client Side).
this problem did not occur when i connect from home.
My question :
any way to fix this issue with c# code or client app.config? or at least fix this with some change in service config (server side).
The only easy solution is to host that service on port 80
The problem is that some networks do not permit outgoing connection to ports other than permitted services(http,https,pop, etc etc)
Or you can ask sysadmins of those networks to permit traffic to your ip/port
If you have iis on that server you could host wcf on iis.
Remenber that only one process can bind to a port on an address at any one time.
there you can find some info: How can a WCF service listen the same port as IIS?

Unable to run SOAP client-server on separate well connected machines

I am having a soap client-server application which runs well on the same machine. Now i want to separate the server-client entities on two different machines. Have done the proper IIS configurations - both the machines are pingable - but the following error occurs at the client side. 209.2.208.160:51645 is the server socket.
There was no endpoint listening at http://209.2.208.160:51645/Service1.asmx that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
For an initial troubleshooting step, I suggest going to the server and running the netstat command to verify that it is listening on port 51645. If it is not, confirm your IIS port settings on the server. MS KB tip on how to view and change these settings for various IIS versions - http://support.microsoft.com/kb/149605.
If the server is listening on port 51645, check to make sure that a firewall is not blocking your incoming client connection on that port - that would explain why your service call works with everything on one machine.

Categories