C# network connection running from shared drive - c#

I'm trying to read web resource fron within the C# code. Unfortunately the code is valid only when running from local drive and throws exception when running from network share (and that's what I need).
The underlying connection was closed: Unable to connect to the remote server.
in System.Net.HttpWebRequest.GetResponse()
.........
Caused by:
An invalid argument was supplied
in System.Net.Sockets.Socket..ctor(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
in System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout)
in System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback)
in System.Net.Connection.CompleteStartConnection(Boolean async, HttpWebRequest httpWebRequest)
I've tried code similar to (this throws the exception):
request = (HttpWebRequest)WebRequest.Create(url);
as well as direct socket connection according to http://msdn.microsoft.com/en-us/library/2b86d684.
I have a suspicion there is some sort of security setting in Windows that prevents network connections. Is it possible to solve this? Via AD policy? Or something in my code?

You could start here The Project Location is Not Trusted Dialog Box. Quote:
By default, a UNC path is not a trusted location for a project. You can modify the security policy of the file share to prevent this dialog box from appearing. For more information, see Configuring Security Policy.

Related

.NET State server: Unable to make the session state request to the session state server

I had an issue with an existing app, so I created a brand new MVC app with no functionality other than reading session state, and I get the same issue.
With this line in the web.config:
<sessionState mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424" cookieless="false" timeout="20" />
I get this when the app runs and tries to utilize session:
"Unable to make the session state request to the session state server."
Full error stack and version info:
[HttpException (0x80070057): Unable to make the session state request to the session state server. Please ensure that the ASP.NET State service is started and that the client and server ports are the same. If the server is on a remote machine, please ensure that it accepts remote requests by checking the value of HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\aspnet_state\Parameters\AllowRemoteConnection. If the server is on the local machine, and if the before mentioned registry value does not exist or is set to 0, then the state server connection string must use either 'localhost' or '127.0.0.1' as the server name.]
System.Web.SessionState.OutOfProcSessionStateStore.MakeRequest(StateProtocolVerb verb, String id, StateProtocolExclusive exclusiveAccess, Int32 extraFlags, Int32 timeout, Int32 lockCookie, Byte[] buf, Int32 cb, Int32 networkTimeout, SessionNDMakeRequestResults& results) +3251784
System.Web.SessionState.OutOfProcSessionStateStore.DoGet(HttpContext context, String id, StateProtocolExclusive exclusiveAccess, Boolean& locked, TimeSpan& lockAge, Object& lockId, SessionStateActions& actionFlags) +169
System.Web.SessionState.OutOfProcSessionStateStore.GetItemExclusive(HttpContext context, String id, Boolean& locked, TimeSpan& lockAge, Object& lockId, SessionStateActions& actionFlags) +26
System.Web.SessionState.SessionStateModule.GetSessionStateItem() +111
System.Web.SessionState.SessionStateModule.BeginAcquireState(Object source, EventArgs e, AsyncCallback cb, Object extraData) +778
System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +254
System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +48
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +159
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3160.0
I have verified the ASP.NET State Service is running, verified that the registry data is accurate, verified the firewall is turned off completely so the local port shouldn't be blocked, etc. What else can I do to verify connectivity with the state server, and what might be going on?
I tried to re-install Framework 4.5, but it was already installed so it didn't do anything. (The app uses Framework 4.5, btw).
I tried the old suggestions of using aspnet_regiis , but that has apparently not been an option in later Framework versions. I see the question asked a few times here, and in other places, but all of them are solved by steps I've already taken, so I'm not sure where to go from here.
Thanks for anyone who can help!
(Edit/addition:
I've also set AllowRemoteConnection to 1 in the registry.
And I verified the service seems to be listening:
C:\WINDOWS\system32>netstat -aon | find /i "42424"
TCP 0.0.0.0:42424 0.0.0.0:0 LISTENING 4256

adding reference for wsdl service in windows service and using its function in c#

I have a windows service using C#(windows application) which performs a set of various functions.
But recently it was required to use a wsdl service (a url was provided) whose functions I have to use in my code.
Although I have never done it before but if I am not wrong we add the service reference creates its instance and then call its function.
I have done all these successfully.
But when i execute the service I get end point not found exception something like as below..
System.ServiceModel.EndpointNotFoundException: Could not connect to http://localhost:8082/quali-jaxrpc/quali. TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:8082. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:8082
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
at System.Net.HttpWebRequest.GetRequestStream()
at System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.GetOutputStream()
--- End of inner exception stack trace ---
The problem is that the service is already running on the server itself but yet it is giving this exception..
Am I doing something wrong?
Please note that my service is not WCF its windows service.
When I added the service reference of the WSDL in appconfig following was created-
<endpoint address="http://localhost:8082/qualicision-jaxrpc/qualicision"
So i just replaced the localhost with the IP of the server.
Although the service is deployed on the server and windows service also running on same but still adding actual IP of the server in place of localhost worked.

Is it possible to get .NET-Remoting MarshalByRefObject work though VPN

I have a client application that needs to access to its server though VPN. If the .NET Remoting call passes serializable objects between server and client, everything works. However, the client app also make a remoting call that passes a MarshalByRefObject argument, this failed because the underlying TCP connection failed to make the connection back to client's.
Unfortunately I don't have control over the corporate VPN setup, and I am not familiar with how VPN works. I tested with all firewall off, but somehow the cooperate VPN network would not allow internal network connect to the external network (client machine). I guess it of make sense to block internal network connect to an external source for security reason. The VPN client in question is Cisco AnyConnect Secure Mobile Client.
My questions are:
Is this a limitation in .NET remoting when using MarshalByRefObject?
If I switch to WCF, would .NET TCP Binding Duplex connection work?
If I can recommend something to the IT department, what should I tell them to configure their VPN (if possible)?
What would be the recommended practice when writing a client-server applications though VPN?
Here is a stack trace when .NET remoting trying to marshal back to the client by failed:
Note: 10.8.26.34 is my client IP Address, and 8080 is the registered for .NET Remoting TCP channel. The ME.Streets.Service.Interface.LoadScheduleHelper is the class that derived from MarshalByRefObject, which has a property call ScheduleKey that need to be marshal to the client for the data.
Exception
System.Net.Sockets.SocketException (0x80004005): 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.8.26.34:8080
Server stack trace:
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
at System.Runtime.Remoting.Channels.RemoteConnection.CreateNewSocket(EndPoint ipEndPoint)
at System.Runtime.Remoting.Channels.RemoteConnection.CreateNewSocket()
at System.Runtime.Remoting.Channels.SocketCache.GetSocket(String machinePortAndSid, Boolean openNew)
at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.SendRequestWithRetry(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream)
at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransportHeaders& responseHeaders, Stream& responseStream)
at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage msg)
Exception rethrown
at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at ME.Streets.Service.Interface.LoadScheduleHelper.get_ScheduleKey()
at ME.Streets.Service.Provider.Remoting.ServiceEndPoints.ServiceEndPoint.LoadScheduleByPrimaryKeyInChunkWorker(LoadScheduleHelper loadScheduleHelper, Boolean loadFromDev) in c:\dev\Streets\Main\Streets\ME.Streets.Service.Provider\Remoting\ServiceEndPoints\ServiceEndPoint.sch_Schedule.cs:line 634
...

Problems FTPing FROM Azure to another FTP site

I've tried using FtpWebRequest and EnterpriseDT.Net.Ftp on an Azure website where I want to pass a byte array from a FileUpload to another FTP site.
This works on local servers and hence will work on a VM but cannot get it working on an Azure website. Admittedly we're trying to avoid the costs of adding a VM or an additional Azure storage account.
It seems the port is blocked on Azure, yet it is open to us on local servers.
[IOException: Failed to connect to XXX.XXX.XXX.XXX:21 within timeout 120000 ms]
EnterpriseDT.Net.StandardSocket.InternalConnect(EndPoint remoteEP, Int32 timeout) +272
EnterpriseDT.Net.StandardSocket.Connect(EndPoint remoteEP, Int32 timeout) +350
EnterpriseDT.Net.Ftp.FTPControlSocket.ConnectSocket(BaseSocket socket, String address, Int32 port) +66
EnterpriseDT.Net.Ftp.FTPControlSocket.Initialize(BaseSocket sock, String remoteHost, Int32 controlPort, Int32 timeout, Encoding encoding) +57
EnterpriseDT.Net.Ftp.FTPClient.Connect(String remoteHost, Int32 controlPort, Int32 timeout) +407
EnterpriseDT.Net.Ftp.FTPClient.Connect() +43
EnterpriseDT.Net.Ftp.FTPConnection.Connect() +456
XXXXX.XXXXX.XXX.XXXXX.FtpUpload(String Id, FileUpload file, String ftpServer, String ftpUsername, String ftpPass, String domainName) +371
Does anyone know how this can be accomplished via .net FtpWebRequest or a third party library?
The FTP port (21) is blocked for an Azure website directly, if you use: ftp://{sitename}.azurewebsites.net, to get the proper FTP profile for that website you need to download it's publishing settings, there you'll find the address, user name and password.
Information on getting the publish profile is here: http://blogs.msdn.com/b/avkashchauhan/archive/2012/06/26/deploying-windows-azure-website-using-visual-studio-web-publish-wizard.aspx
I would also recommend you use the VFS endpoint of your scm site (https://{sitename}.scm.azurewebsites.net) to upload files, this way you use https protocol which is more reliable.
The VFS api:
https://github.com/projectkudu/kudu/wiki/REST-API#vfs
More about your scm site:
http://blogs.msdn.com/b/windowsazure/archive/2014/03/04/windows-azure-websites-online-tools-you-should-know-about.aspx

A connection attempt failed because the connected party did not properly respond after a period of time or connected host has failed to respond

I'm developing a windows service, that downloads images from a specific URL. The service runs correctly on my computer but when I install it in the server it does not download the image and it gives the following error:
System.Net.WebException: Unable to connect to the remote server --->
System.Net.Sockets.SocketException: 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 212.100.220.117:80
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
at System.Net.WebClient.DownloadData(Uri address)
at System.Net.WebClient.DownloadData(String address)
What might be causing the error and how can I resolve it?
I read this page:
http://support.microsoft.com/kb/318140
I'm not sure if this is the problem, and if it is what proxy should I write in the config. Asking you for your advice.
I found the answer. I was trying to access the public address "http://mywebsite.com/images/" from the server. Instead of that I used the local IP of the server hosted the website and it's now working.
In this case it might be possible that port 80 is not open. Create an inbound and outbound rule in firewall setting to open port 80. Still, if the issue exists try with disabling the antivirus, It might be possible that antivirus is blocking the port.
In my case I had to modify the Logon settings of the Windows Service in the Windows Service console then used domain administrator account to run the service instead of the regular Local System/Service account then It started working properly.
If you are working, this could indicate that you aren't connected to your VPN.

Categories