Solved

Execute an URL in a WCF services

Posted on 2010-08-30
13
977 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:Sybux
  • 7
  • 6
13 Comments
 
LVL 30

Expert Comment

by:MlandaT
ID: 33558093
What is the output format of that URL? Does it emit any response?
0
 

Author Comment

by:Sybux
ID: 33558155
Yes it send an html page in response, but I don't really care in my case.
0
 
LVL 30

Expert Comment

by:MlandaT
ID: 33558198
Is that HTML page the one that may contain the messages?
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 30

Expert Comment

by:MlandaT
ID: 33558235
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
 
LVL 30

Expert Comment

by:MlandaT
ID: 33558252
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
 

Author Comment

by:Sybux
ID: 33558482
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
 

Author Comment

by:Sybux
ID: 33558489
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
 
LVL 30

Accepted Solution

by:
MlandaT earned 500 total points
ID: 33558607
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
 

Author Comment

by:Sybux
ID: 33558786
Thx, it's working, but isn't it possible to get the same result with inside function ?
0
 
LVL 30

Expert Comment

by:MlandaT
ID: 33559016
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
 

Author Comment

by:Sybux
ID: 33559038
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
 
LVL 30

Expert Comment

by:MlandaT
ID: 33559201
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
 

Author Comment

by:Sybux
ID: 33559249
Yes you're right. Thx for your help.-
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need a starter for ETL protocol? 4 55
asp day pilot 3 18
Output Caching in IIS 2 28
how to change the view engine in visual studio 2015 enterprises edition 7 43
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question