Proxy problems - please help

Discussion in 'ASP .Net Web Services' started by Keith-Earl, Dec 10, 2003.

  1. Keith-Earl

    Keith-Earl Guest

    I wrote a simple web service a year ago that runs on the clean side of our
    firewall. It posts to remote Internet server which sends an alpha page to
    my pager. Pretty dandy until last week. It broke, my connection was
    refused, not by the remote server but by the ISA proxy.

    I read every newsgroup and KB article I could find. Most suggested
    modifying the machine.config or web.config file which I did. I also tried
    to log into the proxy in code. Once I changed the machine.config file I did
    get further (see below).

    What am I doing wrong? This code worked reliably for a year.

    Thanks,

    Keith


    <WebMethod()> _
    Public Function SendPageProxy(ByVal strPagerID As String, ByVal strMsg
    As String) As String

    Try

    'assign the proxy
    Dim myProxy As New
    WebProxy("http://www-proxy.thedomain.com:8080", True)
    myProxy.Credentials = New NetworkCredential("User", "Pass",
    "Domain")

    strMsg = strMsg.Substring(0, x)

    'Build HttpWebRequest, assign to pager web page
    Dim lcUrl As String = "http://thedomain.com/target/send150.pl"
    Dim wReq As HttpWebRequest = WebRequest.Create(lcUrl)

    'Build POST data
    Dim strPostData As String = "host=" +
    HttpUtility.UrlEncode("192.168.1.5") & "&pagerid=" +
    HttpUtility.UrlEncode(strPagerID) & "&msg=" + HttpUtility.UrlEncode(strMsg)
    & "&submit.x=" + HttpUtility.UrlEncode("18") & "&submit.y=" +
    HttpUtility.UrlEncode("18")
    wReq.Method = "POST"
    wReq.ContentType = "application/x-www-form-urlencoded"

    'Get length of POST data, set in Request
    Dim bytePostBuffer As Byte() =
    System.Text.Encoding.GetEncoding(1252).GetBytes(strPostData)
    wReq.ContentLength = bytePostBuffer.Length

    'Write out the Post data
    ===>works Dim streamPostData As Stream = wReq.GetRequestStream() '<===
    THIS STATEMENT used to BOMB before I changed the machine.config
    streamPostData.Write(bytePostBuffer, 0, bytePostBuffer.Length)

    streamPostData.Close()

    Dim wRes As HttpWebResponse
    ===>bombs wRes = wReq.GetResponse() '<=== THIS STATEMENT BOMBS

    Dim enc As Encoding = System.Text.Encoding.GetEncoding(1252)
    Dim srResponseStream As StreamReader = New
    StreamReader(wRes.GetResponseStream(), enc)
    Dim strHtml As String = srResponseStream.ReadToEnd()

    wRes.Close()
    srResponseStream.Close()

    'if the ResponseStream contains the word "successfully" assume
    it was successful
    If InStr(strHtml, "successfully", CompareMethod.Text) Then
    Return "Successful"
    Else
    Return strHtml
    End If


    Catch ex As Exception
    Return ex.Message()
    Finally

    End Try
    End Function

    machine.config change

    <defaultProxy>

    <!-- KAR 10-Dec-03 -->
    <proxy usesystemdefault="false"
    proxyaddress="http://www-proxy.thedomain.com:8080"
    bypassonlocal="true" />
     
    Keith-Earl, Dec 10, 2003
    #1
    1. Advertising

  2. The reason it is failing is probably because your network config changed,
    without your knowledge.

    To get this to work, I believe you should be attaching the proxy to the
    WebRequest, before writing the POST data.

    wReq.Proxy= myProxy ;




    "Keith-Earl" <css@NO_SPAMConsultWithUs.com> wrote in message
    news:...
    > I wrote a simple web service a year ago that runs on the clean side of our
    > firewall. It posts to remote Internet server which sends an alpha page

    to
    > my pager. Pretty dandy until last week. It broke, my connection was
    > refused, not by the remote server but by the ISA proxy.
    >
    > I read every newsgroup and KB article I could find. Most suggested
    > modifying the machine.config or web.config file which I did. I also tried
    > to log into the proxy in code. Once I changed the machine.config file I

    did
    > get further (see below).
    >
    > What am I doing wrong? This code worked reliably for a year.
    >
    > Thanks,
    >
    > Keith
    >
    >
    > <WebMethod()> _
    > Public Function SendPageProxy(ByVal strPagerID As String, ByVal strMsg
    > As String) As String
    >
    > Try
    >
    > 'assign the proxy
    > Dim myProxy As New
    > WebProxy("http://www-proxy.thedomain.com:8080", True)
    > myProxy.Credentials = New NetworkCredential("User", "Pass",
    > "Domain")
    >
    > strMsg = strMsg.Substring(0, x)
    >
    > 'Build HttpWebRequest, assign to pager web page
    > Dim lcUrl As String = "http://thedomain.com/target/send150.pl"
    > Dim wReq As HttpWebRequest = WebRequest.Create(lcUrl)
    >
    > 'Build POST data
    > Dim strPostData As String = "host=" +
    > HttpUtility.UrlEncode("192.168.1.5") & "&pagerid=" +
    > HttpUtility.UrlEncode(strPagerID) & "&msg=" +

    HttpUtility.UrlEncode(strMsg)
    > & "&submit.x=" + HttpUtility.UrlEncode("18") & "&submit.y=" +
    > HttpUtility.UrlEncode("18")
    > wReq.Method = "POST"
    > wReq.ContentType = "application/x-www-form-urlencoded"
    >
    > 'Get length of POST data, set in Request
    > Dim bytePostBuffer As Byte() =
    > System.Text.Encoding.GetEncoding(1252).GetBytes(strPostData)
    > wReq.ContentLength = bytePostBuffer.Length
    >
    > 'Write out the Post data
    > ===>works Dim streamPostData As Stream = wReq.GetRequestStream() '<===
    > THIS STATEMENT used to BOMB before I changed the machine.config
    > streamPostData.Write(bytePostBuffer, 0, bytePostBuffer.Length)
    >
    > streamPostData.Close()
    >
    > Dim wRes As HttpWebResponse
    > ===>bombs wRes = wReq.GetResponse() '<=== THIS STATEMENT BOMBS
    >
    > Dim enc As Encoding = System.Text.Encoding.GetEncoding(1252)
    > Dim srResponseStream As StreamReader = New
    > StreamReader(wRes.GetResponseStream(), enc)
    > Dim strHtml As String = srResponseStream.ReadToEnd()
    >
    > wRes.Close()
    > srResponseStream.Close()
    >
    > 'if the ResponseStream contains the word "successfully" assume
    > it was successful
    > If InStr(strHtml, "successfully", CompareMethod.Text) Then
    > Return "Successful"
    > Else
    > Return strHtml
    > End If
    >
    >
    > Catch ex As Exception
    > Return ex.Message()
    > Finally
    >
    > End Try
    > End Function
    >
    > machine.config change
    >
    > <defaultProxy>
    >
    > <!-- KAR 10-Dec-03 -->
    > <proxy usesystemdefault="false"
    > proxyaddress="http://www-proxy.thedomain.com:8080"
    > bypassonlocal="true" />
    >
    >
     
    Dino Chiesa [Microsoft], Dec 11, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vidy5300
    Replies:
    0
    Views:
    876
    vidy5300
    Jun 7, 2004
  2. KK
    Replies:
    2
    Views:
    617
    Big Brian
    Oct 14, 2003
  3. Replies:
    0
    Views:
    1,646
  4. Karsten Wutzke
    Replies:
    1
    Views:
    882
    Steven Simpson
    Aug 20, 2007
  5. Klein Stéphane
    Replies:
    3
    Views:
    597
    Steve Holden
    Dec 20, 2009
Loading...

Share This Page