I'm using the WCF4.0 template -REST. I'm trying to make a method that uploads a file using a stream.
The problem always occur at
Stream serverStream = request.GetRequestStream();
Class for streaming:
namespace LogicClass
{
public class StreamClass : IStreamClass
{
public bool UploadFile(string filename, Stream fileStream)
{
try
{
FileStream fileToupload = new FileStream(filename, FileMode.Create);
byte[] bytearray = new byte[10000];
int bytesRead, totalBytesRead = 0;
do
{
bytesRead = fileStream.Read(bytearray, 0, bytearray.Length);
totalBytesRead += bytesRead;
} while (bytesRead > 0);
fileToupload.Write(bytearray, 0, bytearray.Length);
fileToupload.Close();
fileToupload.Dispose();
}
catch (Exception ex) { throw new Exception(ex.Message); }
return true;
}
}
}
REST project:
[WebInvoke(UriTemplate = "AddStream/{filename}", Method = "POST", BodyStyle = WebMessageBodyStyle.Bare)]
public bool AddStream(string filename, System.IO.Stream fileStream)
{
LogicClass.FileComponent rest = new LogicClass.FileComponent();
return rest.AddStream(filename, fileStream);
}
Windows Form project: for testing
private void button24_Click(object sender, EventArgs e)
{
byte[] fileStream;
using (FileStream fs = new FileStream("E:\\stream.txt", FileMode.Open, FileAccess.Read, FileShare.Read))
{
fileStream = new byte[fs.Length];
fs.Read(fileStream, 0, (int)fs.Length);
fs.Close();
fs.Dispose();
}
string baseAddress = "http://localhost:3446/File/AddStream/stream.txt";
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(baseAddress);
request.Method = "POST";
request.ContentType = "text/plain";
Stream serverStream = request.GetRequestStream();
serverStream.Write(fileStream, 0, fileStream.Length);
serverStream.Close();
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
int statusCode = (int)response.StatusCode;
StreamReader reader = new StreamReader(response.GetResponseStream());
}
}
I've turned off the firewall and my Internet connection, but the error still exists. Is there a better way of testing the uploading method?
Stack trace:
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)
"Actively refused it" means that the host sent a reset instead of an ack when you tried to connect. It is therefore not a problem in your code. Either there is a firewall blocking the connection or the process that is hosting the service is not listening on that port. This may be because it is not running at all or because it is listening on a different port.
Once you start the process hosting your service, try netstat -anb (requires admin privileges) to verify that it is running and listening on the expected port.
update: On Linux you may need to do netstat -anp instead.
You don't have to restart the PC. Restart IIS instead.
Run -> 'cmd'(as admin) and type "iisreset"
You must set up your system proxy
You have to go through this path
controlpanel>>internet option>>connnection>>LAN settings>>
proxy
no tik:use proxy server
I got a similar error message like TCP error code 10061: No connection could be made because the target machine actively refused it in my current project. I find this 10061 error code cannot distinguish the case that the service endpoint is not started and the case that it is blocked by the firewall. Often, the firewall can be switched off, but the problem is still there.
You can test your code in the below two ways.
Insert code to get time A that service is started and time B that client sends the request to the server. If B is earlier than A, it can cause this problem.
Change your server port to another port that is also available in the system. You will find the same error code reported.
Above is my fix. It works on my machine. I hope it helps!
Check if any other program is using that port.
If an instance of the same program is still active, kill that process.
I had a similar issue. In my case the service would work fine on the developer machine but fail when on a QA machine. It turned out that on the QA machine the application wasn't being run as an administrator and didn't have permission to register the endpoint:
HTTP could not register URL http://+:12345/Foo.svc/]. Your process does
not have access rights to this namespace (see
http://go.microsoft.com/fwlink/?LinkId=70353 for details).
Refer here for how to get it working without being an admin user: https://stackoverflow.com/a/885765/38258
If you use WCF storm, can you even log-in to the WCF service endpoint? If not, and you are hosting it in a Windows service, you probably forgot to register that namespace. It's not very well advertised that this step is required, and it is actually annoying to do.
I use this tool to do this; it automates all those cumbersome steps.
Check whether the port number in file Web.config of your webpage is the same as the one that is hosted on IIS.
I had the same problem on my web server "No connection could be made because the target machine actively refused it 161.x.x.235:5672". I asked the Admin to open the port 5672 on the web server, then it worked fine.
I had a similar problem
rejecting localhost and 127.0.0.1.
cmd(admin) netstat -anb found the port running on 169.254.80.80 (dont know were that ip came from because my network ip was 10.0.0.5.
after putting in this IP it worked.
This Gives correct IP:
IPAddress ipAddress = ipHostInfo.AddressList[0];
Console.WriteLine(ipAddress.ToString());
I also faced problem in .Net Remoting Service in C#.
I got it solved in 3 steps:
Change Port of Protocol in all the files whereever it is being used.
Run your Host Server Program and make it active.
Now run your client program.
I could not restart IIexpress. This is the solution that worked for me
Cleaned the build
Rebuild
With this error I was able to trace it, thanks to #Yaur, you need to basically check the service (WCF) if it's running and also check the outbound and inbound TCP properties on your advance firewall settings.
With similar pattern, my rest client is calling the service API, the service called successfully when debugging, but not working on the published code. Error was: Unable to connect to the remote server.
Inner Exception: System.Net.Sockets.SocketException (0x80004005): No connection could be made because the target machine actively refused it serviceIP:443 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, Exception& exception)
Resolution: Set the proxy in Web config.
<system.net>
<defaultProxy useDefaultCredentials="true">
<proxy proxyaddress="http://proxy_ip:portno/" usesystemdefault="True"/>
</defaultProxy>
</system.net>
I had a similar issue. In my case VPN proxy app such as Psiphon ، changed the proxy setup in windows so follow this :
in Windows 10, search change proxy settings and turn of use proxy server in the manual proxy
Make Sure all services used by your application are on, which are using host and port to utilize them . For e.g, as in my case, This error can come, If your application is utilizing a Redis server and it is not being able to connect to it on given port and host, thus producing this error .
For my case, I had an Angular SLA project template with ASP.NET Core.
I was trying to run the IIS Express from the Visual Studio WebUI solution, triggering the "Actively refused it" error.
The problem, in this case, wasn't connected with the Firewall blocking the connection.
It turned out that I had to run the Angular server independently of the Kestrel run because the Server was expecting the UI to run on a specific port but wasn't actually.
For more information, check the official Microsoft documentation.
I had similar problem. In launchSettings, my IIS Express was configured on one port, and there was another launch profile that started on another ApplicationUrl with another port.
Starting the web app up with the IIS Express profile led me to have the error.
I am using the Apache ActiveMQ Artemis AMQP message broker. I started getting the "No connection could be made because the target machine actively refused it" exception when trying to send and receive messages with the broker after a reboot. On a computer where the same type of broker still worked, netstat -anb showed that the broker was listening on the expected port 5672. On the computer with the error, the broker was not listening. On the computer with the error, starting the broker resulted in the following warning's appearing in Microsoft Event Viewer's "Windows Logs > System":
The system failed to register host (A or AAAA) resource records for network adapter
with settings:
Adapter Name : {286EE2DA-3D81-41AE-VE5G-5D761FD3925E}
Host Name : mypc
Primary Domain Suffix : myco.com
DNS server list :
55.77.168.1, 74.86.130.1
Sent update to server : 186.952.335.157:45
IP Address(es) :
182.269.1.437
Either the DNS server does not support the DNS dynamic update protocol or the authoritative zone for the specified DNS domain name does not accept dynamic updates.
To register the DNS host (A or AAAA) resource records using the specific DNS domain name and IP addresses for this adapter, contact your DNS server or network systems administrator.
I was able to use the broker without error after I ran the following in a cmd.exe with administrative privileges, rebooted, and waited about fifteen minutes:
ipconfig /flushdns
ipconfig /renew
ipconfig /registerdns
I am attempting to test my AWS EC2 WordPress application that uses nginx & php-fpm for managing incoming requests.
I don't have the means to test the site using the SSL certificate name which is installed onto the ALB, so this has to be done internally and directly at the EC2 instance. It will soon become apparent that my knowledge of WordPress hosting is limited.
I've adopted port forwarding as a means to connect to the application which is detailed here in this article: https://aws.amazon.com/blogs/aws/new-port-forwarding-using-aws-system-manager-sessions-manager/. So by using the following command I can achieve this:
aws ssm start-session --target i-xxxxxxxxxxxxxx --profile username --region eu-west-1 --document-name AWS-StartPortForwardingSession --parameters '{"portNumber":["80"],"localPortNumber":["9999"]}'
I can get the default nginx page to appear if I run http://localhost:9999 from a browser. What I prefer to do is see if I can hit any of the php WordPress pages. This bit is unclear to me. If I this time access http://localhost:9999/site-1 then I encounter a 404. Then by looking in the /var/log/nginx/error.log I see this in more detail.
*[error] 26041#26041: 1 open() "/usr/share/nginx/html/site-1" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET /whitelines HTTP/1.1", host: "localhost:9999".*
This is further confusion since when I check the EC2 filesystem, I find the site-1 directory structure containing all of the php files under a different location /var/www/site-1.
Not sure why this works using the SSL Certificate name -> ALB -> TG -> EC2 but not by going directly at the EC2.
I suppose what I want to do is, if it possible to verify the sites work without using the Cert ALB route? If so then where am I going wrong?
Thanks!
Following the instructions from https://github.com/voryx/Thruway I am trying to set up a websocket server on localhost (Windows) which will only give me WebSocket connection to 'ws://127.0.0.1:9090/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
I started the server via > php vendor/voryx/thruway/Examples/SimpleClient.php which gives me the following console output:
2016-11-19T18:58:56.4982780 notice [Thruway\Peer\Client 308] Changing PHP precision from 14 to 16
2016-11-19T18:58:56.5007740 info [Thruway\Peer\Client 308] New client created
2016-11-19T18:58:56.5016600 info [Thruway\Transport\PawlTransportProvider 308] Starting Transport
on the client side I am using the recommended example from https://github.com/crossbario/autobahn-js. Which should work - I could successfully connect to the testserver ws://demo.thruway.ws:9090.
Tested in latest Chrome on Windows 10 php7.
Any help or hints would be highly appreciated.
I'm not sure if it's just a typo, but the example router is SimpleWsRouter.php not SimpleClient.php
I have an issue that is most probably a user rights issue.
I have a php script that connects using PDO to a sphinx db.
$sp = new PDO('mysql:host=127.0.0.1;port=9306;dname=', '', '');
When I run it from terminal using root account it works fine. But,
when I attempt to run it through browser as user apache I get the following error:
[Thu Mar 20 11:22:51 2014] [error] [client 98.12.26.274] PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (13)' in /var/www/html/surveys/test.php:3\nStack trace:\n#0 /var/www/html/surveys/test.php(3): PDO->__construct('mysql:host=127....', '', '')\n#1 {main}\n thrown in /var/www/html/surveys/test.php on line 3
There has to be something that is missing the propoer user rights but I have no clue what files I need to give rights to for this to work.
UPDATE:
I realized that selinux was blocking the port. How do I enable that port for apache using selinux?
Just use a socket instead of the IP address? See the manual for an example. This circumvents the network stack altogether.
Put something like
listen=/tmp/mysql_sphinx.sock
into the sphinx.cnf and put the same socket into the DNS of PDO like
$db = new PDO('mysql:dbname=testdb;unix_socket=/tmp/mysql_sphinx.sock');
This frees you from the need to make MySQL accessible over the network too. This is better taking security into account.
My project uses PHP JavaBridge, I have installed WAMP, JRE 6.0, and Tomcat 6.0.32
I can now access http://localhost:8080/ successfully but when I run my PHP site it gives me the following error
warning: fsockopen() [function.fsockopen]: unable to connect to localhost:8080 (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. )
Can anyone please help me with this issue?
EDIT
Forgot to mention that I am using Windows 7
My comment above worked as a solution and hence this answer, so that in future others get it.
Can you 127.0.0.1:8080 instead of localhost:8080? See what do you get?
fsocketopen takes the hostname and it should be a valid domain, in your case, (in general) it could be a valid domain as long as you have an entry for localhost in your hosts file (C:\Windows\System 32\drivers\etc\hosts). See if you have something similar to that.