1
votes

I am working on a 'Smart Device Project' using .Net Framework 3.5. I am trying to connect to some Java SOAP services on a remote server.
In order to do that, I added 'Web References' to my project.

When I try to call my web service I get a WebException 'Unable to connect to the remote server' with the inner exception being 'No connection could be made because the target machine actively refused it'.

I searched quite a lot on the Web and StackOverflow and found a lot of ASP configuration and 'Unavaliable port' answers, but as I have another application using the exact same Service successfully, I can't get why the new one isn't getting through (It did sometimes through my tests so I suppose my client implementation isn't that bad)

I tried to look if there was some connection issue on the port by using some TcpClient:

            System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient();
            try
            {
                client.Connect("myServerName", 8087);
                MessageBox.Show("Success");
            } catch (Exception ex)
            {
                MessageBox.Show("Failure");
            }
            finally
            {
                client.Close();
            }

This connection succeed.

Here is a sample on how I call my WebService:

WSServiceExtended srv = new WSServiceExtended();
srv.Proxy = new System.Net.WebProxy();
ServeurWSI wsi = new ServeurWSI();
srv.Url = "http://myServerName:8087/myServerApp/services/myService";
wsr = srv.login(wsi);

The service is called 'Extended' because I overrided the auto-generated one in order to add Cookie managment since I am using the Compact Framework. Following the sample in this thread: https://social.msdn.microsoft.com/Forums/en-US/34d88228-0b68-4fda-a8cd-58efe6b47958/no-cookies-sessionstate-in-compact-framework?forum=vssmartdevicesvbcs

EDIT:
I made some new tests with the Web references and got it to work.
When I add the Web Reference, I have to put some Url to the Web Service. When I set it with the actual hostname instead of the 'localhost' everything is fine. But then, since I set it manually to the real address just before the call, it shouldn't matter

srv.Url = "http://myServerName:8087/myServerApp/services/myService";

EDIT2:
I might have forgotten some specifics about my environnement.
The Web Services are exposed on my computer on some Tomcat Server.
The application I am working on is also developped on this computer (That's why I can add Web References by putting 'localhost' in the address)
The application is then deployed on a distant device (Windows CE) that will make calls the Web Services through WIFI (There, localhost wouldn't work then)

I tried calling the Web services from other computers successfully.

I'm beginning to think that there might be some differential between the called Url and the one that is set, otherwise, how would I have a difference in behaviour such as the one described in the first edit?

EDIT3:
Well..Seems like it's not a network issue but a .Net compact framework (usage?) issue...
The Url property of the Web Service implementation is simply ignored and the one in the Reference.cs is used in place.


If someone had some idea on how I could troubleshot this, I would really appreciate it.

3

3 Answers

3
votes

That error means that you reached a server and the server said "no way". So you're either hitting the wrong server or the wrong port.

I find the telnet client is useful for testing stuff like this. From the command line, you can do:

telnet [servername] [port]

So something like:

telnet myServerName 8087

If it goes to a blank screen, then it connected successfully. If it does not connect, it'll tell you.

The telnet client is no longer installed by default in Windows 7+, so you'll have to install it. See here for instructions: https://technet.microsoft.com/en-ca/library/cc771275

If the connection does open, you could paste in an actual HTTP request to see what happens. A simple GET would look something like this:

GET /myServerApp/services/myService HTTP/1.1
Host: myServerName:8087
2
votes

One reason for this error can be that the service binds to only a certain IP address. It could well be that the service only listens on the IP that is assigned to the host name, but not on the localhost IP (127.0.0.1).

For example:
If the host myServerName has the public IP 192.168.0.1, your service can choose to listen on all IPs assigned to the host (sometimes specifying 0.0.0.0), or it can specifically listen on 192.168.0.1 only. In that case you will not be able to connect through 127.0.0.1, because the service simply doesn't listen on that IP.

You can "use" this inverse of this feature to make a service accessible only to local clients, not on the public IP-Address, by listening on 127.0.0.1 only, but not on the public IP. This is sometimes used on Linux for example to make MySQL only accessible on the host itself.

0
votes

I was starting to forget this post but I finally found the problem that was messing things up and it has nothing to do with programmation.

I was doing the calls while the device was connected to the computer via the 'Windows Mobile Device Center' allowing to access the device from Windows. While connected, the host provided is ignored and all calls on the specified port are handled by the connected computer. Disconnecting the device allows to communicate properly...