Execute an URL in a WCF services

Hi all,

I need to execute an URL inside a Web services to manage a remote device. The format of my url is http://10.10.10.10/tgi/status.tgi?poweron=poweron for example.

Actually I'm running a shell command to execute a curl but it's not so nice and I can't get a feedback error if needed.

I've search around and seen some things like WebClient or WebRequest but it fails to run with an error message (Connection has been closed)

Thx for help

Sybux
SybuxAsked:
Who is Participating?
 
MlandaTCommented:
Here is a hack .... Your HTML code should hopefully be in the string 'output'
Dim process As New Process()
Dim FileName As String = "curl"
Dim Arguments As String = "-d ""hide=170&btnHide=Submit"" http://10.136.128.102/tgi/status.tgi"
process.StartInfo.UseShellExecute = False
process.StartInfo.RedirectStandardOutput = True
process.StartInfo.RedirectStandardError = True
process.StartInfo.CreateNoWindow = True
process.StartInfo.FileName = FileName
process.StartInfo.Arguments = Arguments
process.StartInfo.WorkingDirectory = WorkingDirectory
process.Start()
Dim output As String = process.StandardOutput.ReadToEnd()

Open in new window

0
 
MlandaTCommented:
What is the output format of that URL? Does it emit any response?
0
 
SybuxAuthor Commented:
Yes it send an html page in response, but I don't really care in my case.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
MlandaTCommented:
Is that HTML page the one that may contain the messages?
0
 
MlandaTCommented:
What happens if you run this?

Try
Dim myClient As WebClient = New WebClient()
Dim response As Stream = myClient.OpenRead("http://10.10.10.10/tgi/status.tgi?poweron=poweron")
response.Close()
Catch ex as Exception
     MsgBox (ex.tostring)
End Try

That should give a more detailed error message which we can use for troubleshooting
0
 
MlandaTCommented:
Do you connect to the machine via a proxy? That may also cause problems.

PS: The code sample I gave you above is meant for a windows forms/console application. Just so that we get it all working there first (easier to troubleshoot).
0
 
SybuxAuthor Commented:
I got the following trace :



System.Net.WebException: La connexion sous-jacente a été fermée : Une erreur inattendue s'est produite lors de la réception. ---> System.IO.IOException: Impossible de lire les données de la connexion de transport : Une connexion existante a dû être fermée par l'hôte distant. ---> System.Net.Sockets.SocketException: Une connexion existante a dû être fermée par l'hôte distant
   à System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   à System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- Fin de la trace de la pile d'exception interne ---
   à System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   à System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   à System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
   --- Fin de la trace de la pile d'exception interne ---
   à System.Net.WebClient.OpenRead(Uri address)
   à System.Net.WebClient.OpenRead(String address)
   à CI_Management.Management.Beamer(String Action, String ComputerName) dans E:\VisualStudioProject\CI_Management\CI_Management\Management.svc.vb:ligne 39

Open in new window

0
 
SybuxAuthor Commented:
and when I run the curl, I got the following output :
D:\Users\wcf>curl -d "hide=170&btnHide=Submit" http://10.136.128.102/tgi/status.tgi
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<head>
<title>Untitled Document</title>
<meta HTTP-EQUIV="Content-Type" CONTENT=
"text/html; charset=ISO-8859-1">
<script LANGUAGE="javascript" SRC="/status.js" TYPE=
"text/javascript">
</script>
</head>
<body TEXT="#333333" LINK="#333333" VLINK="#333333" ALINK="#333333"
LEFTMARGIN="0" TOPMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0"
LANGUAGE="javascript" ONLOAD="window_onload()">
<form NAME="form1" METHOD="post" ACTION="/tgi/status.tgi">
<input TYPE="hidden" NAME="PJSTATE" VALUE="1">
<input TYPE="hidden" NAME="DSP_SOURCE" VALUE="117">
<input TYPE="hidden" NAME="ERRORSTA" VALUE="">
<input TYPE="hidden" NAME="FREEZE0" VALUE="">
<input TYPE="hidden" NAME="HIDE0" VALUE="170">
<table WIDTH="100%" HEIGHT="100%" BORDER="0" CELLPADDING="0"
CELLSPACING="0">
<tr>
<td WIDTH="1" BGCOLOR="#333333"></td>
<td VALIGN="top">
<table WIDTH="634" HEIGHT="420" BORDER="0" CELLPADDING="2"
CELLSPACING="2">
<tr>
<td WIDTH="6" HEIGHT="23">&nbsp;</td>
<td WIDTH="707"><font COLOR="#0066CC" SIZE="5" FACE=
"Arial, Helvetica, sans-serif"><strong>Projector Status and Control </strong></font></td></tr>
<tr>
<td HEIGHT="23" WIDTH="6">&nbsp;</td>
<td WIDTH="707">&nbsp;</td></tr>
<tr>
<td HEIGHT="356" WIDTH="6">&nbsp;</td>
<td VALIGN="top" WIDTH="707">
<table WIDTH="622" BORDER="0" CELLSPACING="0" CELLPADDING="0"
HEIGHT="605">
<tr>
<td HEIGHT="19" WIDTH="620"><strong><font SIZE="2" FACE=
"Arial, Helvetica, sans-serif">Projector Status </font></strong></td></tr>
<tr>
<td HEIGHT="427" WIDTH="620">
<table WIDTH="623" BORDER="0" CELLSPACING="2" CELLPADDING="2"
HEIGHT="569">
<tr>
<td WIDTH="142" HEIGHT="29"><font SIZE="2" FACE=
"Arial, Helvetica, sans-serif">Projector Status </font></td>
<td WIDTH="198" HEIGHT="29" COLSPAN="2"><input NAME="PJSTATE2"
       TYPE="text" VALUE="Lamp ON " SIZE="25"></td>
<td HEIGHT="29"><input NAME="PowerOn" STYLE="width: 90; height: 25"
TYPE="submit" VALUE="Power ON ">&nbsp; <input NAME="PowerOff"
STYLE="width: 90; height: 25" TYPE="submit" VALUE=
"Power OFF "></td></tr>
<tr>
<td WIDTH="142" HEIGHT="27"><font SIZE="2" FACE=
"Arial, Helvetica, sans-serif">Power Saving </font></td>
<td WIDTH="198" HEIGHT="27" COLSPAN="2"><font SIZE="2" FACE=
"Arial, Helvetica, sans-serif"><select NAME="PwSave" STYLE=
"width: 190">
<option VALUE="99" >----------------Select---------------- </option>
<option VALUE="0" SELECTED>Off </option>
<option VALUE="5" >5 min. </option>
<option VALUE="15" >15 min. </option>
<option VALUE="30" >30 min. </option>
<option VALUE="45" >45 min. </option>
<option VALUE="60" >
60 min. </option></select></font></td>
<td COLSPAN="2" HEIGHT="27" WIDTH="257"><input TYPE="submit"
       NAME="btnPwSave" VALUE="Submit "></td></tr>
<tr>
<td WIDTH="142" HEIGHT="25"><font SIZE="2" FACE=
"Arial, Helvetica, sans-serif">Lamp Hours </font></td>
<td WIDTH="198" HEIGHT="25" COLSPAN="2"><input NAME="LAMPHR"
       TYPE="text" VALUE="608 hr." SIZE="25"></td>
<td COLSPAN="2" HEIGHT="25" WIDTH="257"></td></tr>
<tr>
<td WIDTH="142" HEIGHT="25"><script LANGUAGE="JavaScript"
        TYPE="text/javascript">
                                                if(parseInt(document.form1.ERRORSTA.value) == 0x55 || parseInt(document.
form1.ERRORSTA.value) == 0) {           //Good
                                                        document.write("<font color=#CCCCCC size=2 face=Arial, Helvetica
, sans-serif>");
                                                } else {
                                                        document.write("<font size=2 face=Arial, Helvetica, sans-serif>"
);
                                                }
</script> Error Status </td>
<td WIDTH="198" HEIGHT="25" COLSPAN="2"><input NAME="ERRORSTA2"
TYPE="text" SIZE="25" VALUE=""></td>
<td COLSPAN="2" HEIGHT="25" WIDTH="257"></td></tr>
<tr>
<td HEIGHT="21" COLSPAN="5" WIDTH="613">
<hr></td></tr>
<tr>
<td HEIGHT="18" COLSPAN="5" WIDTH="613"><strong><font SIZE="2"
      FACE="Arial, Helvetica, sans-serif">Image Control </font></strong></td></tr>
<tr>
<td WIDTH="142" HEIGHT="27"><font SIZE="2" FACE=
"Arial, Helvetica, sans-serif">&nbsp;Operation Mode </font></td>
<td WIDTH="102" HEIGHT="27"><font SIZE="2" FACE=
"Arial, Helvetica, sans-serif"><input TYPE="radio" VALUE="28"
       NAME="ecoMode" CHECKED>Full Power </font></td>
<td WIDTH="106" HEIGHT="27"><font SIZE="2" FACE=
"Arial, Helvetica, sans-serif"><input TYPE="radio" VALUE="27"
       NAME="ecoMode" >ECO Mode </font></td>
<td COLSPAN="2" HEIGHT="27" WIDTH="257"><input TYPE="submit"
       NAME="btnECOMode" VALUE="Submit "></td></tr>
<tr>
<td WIDTH="142" HEIGHT="27"><font SIZE="2" FACE=
"Arial, Helvetica, sans-serif">&nbsp;Projection Mode </font></td>
<td WIDTH="198" HEIGHT="27" COLSPAN="2"><font SIZE="2" FACE=
"Arial, Helvetica, sans-serif"><select NAME="PrjMode"
        STYLE="width: 190">
<option VALUE="99" >---------------Select--------------- </option>
<option VALUE="0" >Rear Projection-Desktop </option>
<option VALUE="1" SELECTED>Front Projection-Ceiling Mount </option>
<option VALUE="2" >Front Projection-Desktop </option>
<option VALUE="3" >
Rear Projection-Ceiling Mount </option></select></font></td>
<td COLSPAN="2" HEIGHT="27" WIDTH="257"><input TYPE="submit"
       NAME="btnPrjMode" VALUE="Submit "></td></tr>
<tr>
<td WIDTH="142" HEIGHT="27"><font SIZE="2" FACE=
"Arial, Helvetica, sans-serif">&nbsp;Source Select </font></td>
<td WIDTH="198" HEIGHT="27" COLSPAN="2"><font SIZE="2" FACE=
"Arial, Helvetica, sans-serif"><select NAME="PrjSRC" STYLE=
"width: 190">
<option VALUE="0" >---------------Select--------------- </option>
<option VALUE="113" >M1 RGB</option>
<option VALUE="114" >M1 DRGB</option>
<option VALUE="115" >M1 Component</option>
<option VALUE="117" SELECTED>VGA RGB</option>
<option VALUE="118" >VGA Component</option>
<option VALUE="120" >BNC RGB</option>
<option VALUE="121" >BNC Component</option>
<option VALUE="123" >RCA Component</option>
<option VALUE="125" >S-Video</option>
<option VALUE="126" >Composite</option>
<option VALUE="127" >
HDMI</option></select></font></td>
<td COLSPAN="2" HEIGHT="27" WIDTH="257"><input TYPE="submit"
       NAME="btnSource" VALUE="Submit "></td></tr>
<tr>
<td WIDTH="142" HEIGHT="27"><font SIZE="2" FACE=
"Arial, Helvetica, sans-serif">&nbsp;Video Mode </font></td>
<td WIDTH="198" HEIGHT="27" COLSPAN="2"><font SIZE="2" FACE=
"Arial, Helvetica, sans-serif"><select NAME="VideoMode"
        STYLE="width: 190">
<option VALUE="99" >---------------Select--------------- </option>
<option VALUE="0" SELECTED>PC Mode </option>
<option VALUE="1" >Movie Mode </option>
<option VALUE="2" >Game Mode </option>
<option VALUE="3" >sRGB Mode </option>
<option VALUE="4" >
User Mode </option></select></font></td>
<td COLSPAN="2" HEIGHT="27" WIDTH="257"><input TYPE="submit"
       NAME="btnVideo" VALUE="Submit "></td></tr>
<tr>
<td WIDTH="142" HEIGHT="27"><font SIZE="2" FACE=
"Arial, Helvetica, sans-serif">&nbsp;Blank screen </font></td>
<td WIDTH="58" HEIGHT="27"><font SIZE="2" FACE=
"Arial, Helvetica, sans-serif"><input TYPE="radio" VALUE="85"
       NAME="hide" >On </font></td>
<td WIDTH="132" HEIGHT="27"><font SIZE="2" FACE=
"Arial, Helvetica, sans-serif"><input TYPE="radio" VALUE="170"
       NAME="hide" CHECKED>Off </font></td>
<td COLSPAN="2" HEIGHT="27" WIDTH="257"><input TYPE="submit"
       NAME="btnHide" VALUE="Submit "></td></tr>
<tr>
<td WIDTH="142" HEIGHT="27"><font SIZE="2" FACE=
"Arial, Helvetica, sans-serif">&nbsp;Aspect Ratio </font></td>
<td WIDTH="108" HEIGHT="27"><font SIZE="2" FACE=
"Arial, Helvetica, sans-serif"><input TYPE="radio" VALUE="1"
       NAME="Aspect" >1:1  &nbsp;
       <input TYPE="radio" VALUE="2" NAME="Aspect"
       >16:9 </font></td>
<td WIDTH="90" HEIGHT="27"><font SIZE="2" FACE=
"Arial, Helvetica, sans-serif"><input TYPE="radio" VALUE="3"
       NAME="Aspect" CHECKED>4:3 </font></td>
<td COLSPAN="2" HEIGHT="27" WIDTH="257"><input TYPE="submit"
       NAME="btnAspect" VALUE="Submit "></td></tr>
<tr>
<td WIDTH="142" HEIGHT="27"><font SIZE="2" FACE=
"Arial, Helvetica, sans-serif">&nbsp;Brightness </font></td>
<td WIDTH="198" HEIGHT="27" COLSPAN="2"><input TYPE="text"
       SIZE="18" MAXLENGTH="3" NAME="Bright" VALUE="44">
       <font SIZE="1" FACE=
       "Arial, Helvetica, sans-serif">(0~100)</font></td>
<td COLSPAN="2" HEIGHT="26" WIDTH="257"><input TYPE="submit"
       NAME="btnBright" VALUE="Submit "></td></tr>
<tr>
<td WIDTH="142" HEIGHT="26"><font SIZE="2" FACE=
"Arial, Helvetica, sans-serif">&nbsp;Contrast </font></td>
<td WIDTH="198" HEIGHT="26" COLSPAN="2"><input TYPE="text"
       SIZE="18" MAXLENGTH="3" NAME="Contrast" VALUE=
       "46"> <font SIZE="1" FACE=
       "Arial, Helvetica, sans-serif">(0~100)</font></td>
<td COLSPAN="2" HEIGHT="26" WIDTH="257"><input TYPE="submit"
       NAME="btnContrast" VALUE="Submit "></td></tr>
<tr>
<td WIDTH="142" HEIGHT="26"><font SIZE="2" FACE=
"Arial, Helvetica, sans-serif"><input NAME="btnAutoAdj"
       STYLE="width: 150; height: 25" TYPE="submit" VALUE=
       "Auto Adjust "></font></td>
<td HEIGHT="26" COLSPAN="3"><font SIZE="2" FACE=
"Arial, Helvetica, sans-serif"><input NAME="btnReset" STYLE=
"width: 129; height: 25" TYPE="submit" VALUE=
"Factory Reset ">&nbsp;&nbsp; <input NAME="btnReload" STYLE=
"width: 129; height: 25" TYPE="submit" VALUE=
"Refresh"></font></td></tr>
<tr>
<td HEIGHT="26" COLSPAN="5" WIDTH="613">
<hr></td></tr>
<tr>
<td HEIGHT="26" COLSPAN="5" WIDTH="613"><strong><font SIZE="2"
      FACE="Arial, Helvetica, sans-serif">Audio Control </font></strong></td></tr>
<tr>
<td WIDTH="142" HEIGHT="26"><font SIZE="2" FACE=
"Arial, Helvetica, sans-serif">&nbsp;Volume </font></td>
<td WIDTH="198" HEIGHT="26" COLSPAN="2"><input TYPE="text"
       SIZE="18" MAXLENGTH="2" NAME="Volume" VALUE="30">
       <font SIZE="1" FACE=
       "Arial, Helvetica, sans-serif">(0~30)</font></td>
<td COLSPAN="2" HEIGHT="26" WIDTH="257"><input TYPE="submit"
       NAME="btnVol" VALUE=
       "Submit"></td></tr></table></td></tr></table></td></tr></table></td></tr></table></form>

</body>
</html>

Open in new window

0
 
SybuxAuthor Commented:
Thx, it's working, but isn't it possible to get the same result with inside function ?
0
 
MlandaTCommented:
What do you mean inside function?

I'm sure it would be possible to still use the WebClient. I suspect that there is a proxy server which we would otherwise need to configure in the vb.NET code.
0
 
SybuxAuthor Commented:
Yes I mean webclient or other vb function. I'm using proxy to access internet of course but as it's internal, no proxy is needed.
0
 
MlandaTCommented:
in your IE... configure it to bypass proxy for local addresses

also.. what is this: hide=170&btnHide=Submit

am not sure we should still worry too much since we have a "working" solution... not extremely elegant... but functional enough :)
0
 
SybuxAuthor Commented:
Yes you're right. Thx for your help.-
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.