Problem accessing TP using C#/.NET code

68 views
Skip to first unread message

Ken Tsoi

unread,
Aug 18, 2016, 11:14:40 PM8/18/16
to DevTargetProcess

Hi Experts,

We are using TargetProcess for stuffs like project management and software release etc, and have developed a tool using C#/.NET to do things like report generation when doing a release. The tool was working well until recently when we upgraded TP to V3.9.2 and move the TP server to another IP address.

I tried to debug the problem, found that the tools stops at the very beginning when it tried to get all the project information, the code is like:
==================================================
        internal static Boolean getAllProjectInfo(List<ProjectInfo> list)
        {
            try
            {
                WebClient client = new WebClient();
                client.Credentials = new NetworkCredential(ConArgs.USER_NAME, ConArgs.USER_PASSWORD);
                var projects = XDocument.Parse(client.DownloadString(ConArgs.TP_URL + string.Format("/api/v1/Projects/?take=1000")));
                //add conditions of the parent node to avoid cases that there are "Project" nodes under the parent "Project" node
                IEnumerable<XElement> category_projects = from p in projects.Descendants("Project") where p.Parent.Name.ToString() == "Projects" select p;
                foreach (XElement item in category_projects)
                {
                    ProjectInfo pi = new ProjectInfo();
                    pi.Id=Convert.ToInt32(item.Attribute("Id").Value);
                    pi.Name=item.Attribute("Name").Value;               
                    list.Add(pi);
                }
                return true;
            }
            catch (WebException ex)
            {
                Console.WriteLine(ex.Message);
                return false;
            }
        }
=================================================

When looking at the exception caught, the message of inner exception shows: "Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host", and the message of the exception shows "The underlying connection was closed: An unexpected error occurred on a send". Please refer to the enclosed screen capture for reference. 

The error code is 10054, which I checked from MSDN is:
WSAECONNRESET
10054

Connection reset by peer.

An existing connection was forcibly closed by the remote host. This normally results if the peer application on the remote host is suddenly stopped, the host is rebooted, the host or remote network interface is disabled, or the remote host uses a hard close (see setsockopt for more information on the SO_LINGER option on the remote socket). This error may also result if a connection was broken due to keep-alive activity detecting a failure while one or more operations are in progress. Operations that were in progress fail with WSAENETRESET. Subsequent operations fail with WSAECONNRESET.



I have verified the USER_NAME and the USER_PASSWORD, should be correct. And have verified the Web request using the web-browser and postman tool from Google, the return result is of no problem.

Do you have any ideas what the problem may be?

Best regards,
Ken

CS_error.png

Ken Tsoi

unread,
Aug 18, 2016, 11:33:22 PM8/18/16
to DevTargetProcess
The problem should be happening on the part:
client.DownloadString(ConArgs.TP_URL + string.Format("/api/v1/Projects/?take=1000"))

As when I tried to break the highlighted code into:
string s = client.DownloadString("https://process.rtx.net/api/v1/Projects/?take=1000");
var projects = XDocument.Parse(s);

The exception was caught in the first line.

Alex Fomin

unread,
Aug 19, 2016, 4:00:17 AM8/19/16
to DevTargetProcess
Targetprocess uses TLS 1.2 for https encryption (as described here https://www.targetprocess.com/blog/2016/03/targetprocess-will-start-enforcing-tls-1-2-encryption/)

To fix your issues add the following line to your code:

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

Ken Tsoi

unread,
Aug 19, 2016, 4:20:07 AM8/19/16
to devtarge...@googlegroups.com
Hi Alex,

Thanks a lot, the problem is solved!

--
You received this message because you are subscribed to a topic in the Google Groups "DevTargetProcess" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/devtargetprocess/8vIAEfZTjtg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to devtargetprocess+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages