Category Archives: Webservice

[RESOLVED] Displaying external HTML within an aspx page

What would be the most efficient way to inject just the contents of an html page into a user control or directly into a page? 

In example if the html page I'm calling consists of a simple <div> layout how could I display that within an aspx page.

Check out UFrame, here you can display external pages inside a DIV tag. http://uframe.codeplex.com/SourceControl/list/changesets, I used in couple of projects and it is pretty cool 

There are many ways of doing this. One way is to use as highlighted by rmaiya (though I have not tried that option). Other options are making use of an iframe and giving the source as that of the html page. Iframes are not considered good. Another option is to make use of the HTTPRequest object in the code behind and get the html stream. Once you have the HTML stream you can use Response.Write or you can use of a literal control and assign the stream to the text property of the literal control. 

Hope this helps.

Sandeep,

Anychance you have an example?

<div style="color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; width: 100%; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; margin: 8px;">

HttpWebRequest and HttpWebResponse - 

http://www.4guysfromrolla.com/demos/HttpWebRequestDemo1.aspx

http://www.codeproject.com/KB/webservices/HttpWebRequest_Response.aspx

Or else just simple use IFrame...

http://geekswithblogs.net/ranganh/archive/2005/04/25/37635.aspx

Thanks.

</div>

This is what I ended up using.  The html is displayed within a user control.

default.aspx

<uc1:external ID="external" URL="http://www.google.com" runat="server" />

external.ascx

<asp:Literal ID="site" runat="server"></asp:Literal>

external.ascx.vb

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.ComponentModel
Imports System.Net

Partial Public Class _test_Head
    Inherits System.Web.UI.UserControl
    <Bindable(True), DefaultValue("")> _
    Public Property URL() As String
        Get
            Return viewstate("urlinclude").ToString()
        End Get
        Set(ByVal Value As String)
            viewstate("urlinclude") = Value
        End Set
    End Property

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        Dim cl As WebClient = New WebClient()
        'cl.BaseAddress = this.URL;
        site.Text = cl.DownloadString(Me.URL)
    End Sub
End Class

[RESOLVED] Extract HTML and save to .html file

Hi guys -

Can someone help me to grab the html of a current page and write it to a folder on the server?  I pieced this together from this thread - http://forums.asp.net/p/1608708/4108619.aspx but I can't quite figure out how to write it to .html file on the server.

Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
        blnLogHTMLtoDB = True
    End Sub

    Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)

        If blnLogHTMLtoDB = True Then

            Dim b As New StringBuilder()
            Dim h As New HtmlTextWriter(New StringWriter(b))
            MyBase.Render(h)
            Dim html As String = b.ToString()
            ' save to filesystem (or whatever you want to do with it)

            Dim objWebClient As New WebClient()
            Dim objStream As Stream = objWebClient.OpenRead(html)
            Dim objStreamReader As New StreamReader(objStream)
            Dim strOutput As String = objStreamReader.ReadToEnd()
            objStream.Close()
            objStreamReader.Close()
            Dim sw As New StreamWriter(Server.MapPath("test.html"))
            strOutput = Regex.Replace(strOutput, "<input type=""hidden"" name=""__VIEWSTATE"" id=""__VIEWSTATE"" value="".*?"" />", "", RegexOptions.IgnoreCase)
            sw.Write(strOutput)
            sw.Close()

        End If

    End Sub

You can use HttpWebRequest and its response to get the html content of the page and then store it in html file...

http://www.codeproject.com/KB/webservices/HttpWebRequest_Response.aspx

for storing in html file you got to use System.IO namepasce and some classes like FileStream...

Thanks.

[RESOLVED] System.Net.Sockets.SocketException: A connection attempt failed error

I am using the codes sample from Peter through this link:http://www.eggheadcafe.com/articles/20030316.asp
to validate email address. I made some minor modification to validate user email address after the user have entered his or her email address as show below

string[] host = (address.Split('@'));
string hostname = host[1];
IPHostEntry IPhst = Dns.Resolve(hostname);
IPEndPoint endPt = new IPEndPoint(IPhst.AddressList[0], 25);
Socket s = new Socket(endPt.AddressFamily,SocketType.Stream, ProtocolType.Tcp);
s.Connect(endPt);


The last line of code s.Connect(endPt) generated the following error if the user email address is anything other than the company email address. I have try gmail, hotmail and they all generated the same error. Can the experts tell me how to get around the problem. Thank you in advance
 
Here is the error:
System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 64.4.20.174:25
   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
   at MGHRadiologyAlert.IfaWebService.ValidateEmailAddress(String address) in

Hi,

The Resolve method queries a DNS server for the IP address associated with a host name or IP address.

I think you can try to use:

string stmpserver = "smtp.gmail.com";
            //string stmpserver = "72.14.213.109";
            IPHostEntry IPhst = Dns.Resolve(stmpserver);
            //IPHostEntry IPhst = Dns.GetHostEntry(stmpserver);
            IPEndPoint endPt = new IPEndPoint(IPhst.AddressList[0], 25);
            Socket s = new Socket(endPt.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            s.Connect(endPt);

Smtp.gmail.com's IP address is 72.14.213.109. You can get it from the this link:http://tracert.com/resolver.html

BTW, seems that the Dns.Resolve method is obsolete, instead, you can use another method:Dns.GetHostEntry

Hope this can help you.

[RESOLVED] "Cannot find table" when I can prove the table is there.

<div sab="273">OK, my friends... this one is driving me absolutely bonkers.</div> <div sab="274">I am filling a dataset with XML data returned from a WebSphere WebService... a-like so:</div> <div sab="274">
        Dim sXML = oWS.web0300_XML(oInput)
        oWS.Dispose()
        Dim xR As New System.IO.StringReader(sXML)
        ds.ReadXml(xR)
        xR.Dispose()
</div> <div sab="274">Works great, and when I do some old-school testing like this:</div> <div sab="274">
        Response.Write("Table 1: " & ds.Tables(1).Rows.Count)
        Response.End()
</div> <div sab="274">I get the number of rows.</div> <div sab="274"></div> <div sab="274">But, when I get rid of the testing code and do this line instead</div> <div sab="274"></div> <div sab="274">
Dim dt As Data.DataTable = ds.Tables(1)
</div> <div sab="274">I get: Cannot find Table 1</div> <div sab="274">Is my server playing a joke on me?  Works in Dev.</div>

Why don't you check ds.Tables.Count ?

The I must say your server has a good sense of humour like you.

Is in same location you are coding now at where you had test code? try to debug and with the help ofquick watch try to examine the dataset.

I am not a vb.net expert (i prefer c#.net) but is your style of assignment code is ok (it seems ok to me)?

 

The reason I don't check for Count is because it won't do me any good.  The reason why it won't do any good is because when I get data from the iSeries program, the iSeries logs the results it has sent so that they cannot be grabbed again unless I get one of the iSeries programmers to clear the log file.

Long story short, once I get back the XML, everything else HAS to run right or the whole thing just goes wonky.

I think instead of reading it into the DataSet, I may just have to access the XML directly, but that still wouldn't explain why this mess is happening in the first place.

I don't think in my 11 years of ASP, I've ever seen the exact same object act two different ways like this.

False alarm!

This was a recursive function, and the problem was happening on a separate iteration through.  Blech....

[RESOLVED] How to use mutil asp.net webcontrol with webservice pooling to render a webpage

My project use asp.net web form, and I code it with masterpage, page and mutil webcontrol to render a web page. A problem, request it slowly. I want to increase performace. I use webservice to request data, whole web control has code to request data from webservice. 

I review code, and I think if my web used webservice pooling to render a webpage, it help increase performance? But I haven't know how to code better, remove all webcontrol, and move their code to create a web page like asp web page (not asp.net)! using only one webservice to request data...

Can you help for me? Thank for your suggestion!

Hi hungudym,

You can use the ajax to comsume the webservice, then fill the data with the webcontrol.

Please check the following link:

http://www.developer.com/net/asp/article.php/3657826/Consuming-Web-Service-Using-ASPNET-AJAX.htm

http://msdn.microsoft.com/en-us/magazine/cc163499.aspx

http://msdn.microsoft.com/en-us/library/bb532367.aspx