Results 1 to 10 of 10

Thread: Use of Web Services in an ASP Application

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2002
    Posts
    32

    Question Use of Web Services in an ASP Application

    We have a requirement in our project wherein we need to get some stock information & display it to the user. The application is pure ASP & VB based. We are wondering whether we can use a web-service to do this job. Want to know if its possible in someway to use Web-Service in an ASP application (thru some COM wrapper). Creating the web-service wont be a problem as .Net Framework will be available to us.


    Anybody any thoughts??

    Thanks in advance,
    Sujala

  2. #2
    Junior Member
    Join Date
    Apr 2003
    Posts
    18
    You have serveral options including:
    Write a VB.NET Assembly and make it COM Compliant
    Write VB6 DLL to access web Services through Winsock,etc

    My question would be why are you wanting to use COM in the first place.

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2002
    Posts
    32

    other than COM?

    Thanks for ur reply.. but what are the other options (other than COM) since we have to plug it in an ASP application. yes, its stupid to use web-services but not develop the application in .Net. but thats how have things gone so far. initially there was no requirement of showing weather information on the site, so the client dint want to use .Net, but now they are "considering" installing .Net framework in the production m/c in order to make the web-service work :-).. thats how clients (& our marketing guyz ) are u know...

    can u throw some light pls on how make a web-service developed either thru C# or VB.Net COM compliant??

    thnks again,
    sujala

  4. #4
    Junior Member
    Join Date
    Apr 2003
    Posts
    18
    the idea behind a web-service is that it can be platform/language independant. Write your web sevice to send and recieve XML. XML is fully supported by ASP, VB6, ASP.NET, VB.NET, Linux, Unix, etc, etc.
    www.WinMgmt.com
    [email protected]

  5. #5
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    right. a .NET web service sends data via XML and SOAP. There are implementtions of this for virtually everything. you dont NEED .NET to access a web service. J2EE for example hs web service accessing and writting stuff. The SOAP toolkit from Microsoft can be used in VB6 and other ActiveX compliant language on Windows. There are tons more. check out xmethods.com and you can see plenty of public web services written on a variety of platforms.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  6. #6
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    I wrote some adhoc webservices a while back using ASP and XML (MSXML COM Objects). If you would like to see an example, let me know.

  7. #7

    Thread Starter
    Member
    Join Date
    Nov 2002
    Posts
    32

    yes pls

    yes, Lethal.. a ready eg. will definitely help. can u copy-paste/upload ur prgrams here?

    thnxalot,
    sujala

  8. #8
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Here is one example:

    Code:
    <%
    Option Explicit
    
    Response.CacheControl = "no-cache"
    Response.ContentType = "text/xml" 
    
    On Error Resume Next
    
    Const adVarChar = 200
    Const adChar = 129
    Const adInteger = 3
    Const adDate = 7
    Const adParamInput = 1
    Const adCmdStoredProc = 4
    
    Dim objConnection 
    Dim objCommand 
    Dim strUserID 
    Dim strPassword
    Dim strConnectionString 
    Dim strXMLRequest   
    Dim xmlDoc
    Dim strDivisionNbr
    Dim strAccountNbr
    Dim strUserName
    Dim strDomainName
    Dim strMachineName
    Dim strRequest
    Dim strResponseCode
    Dim strOperatorID
    Dim strRegions
    Dim strPurgeDate
    Dim strStatus
    Dim strAssociateId
    Dim xmlResponseDoc
    Dim xmlErrorDoc
    
    Set objConnection = CreateObject("ADODB.Connection")
    Set objCommand = CreateObject("ADODB.Command") 
    Set xmlDoc = CreateObject("Microsoft.XMLDOM")
    Set xmlResponseDoc = CreateObject("Microsoft.XMLDOM")
    
    'Convert the Byte Code to Ascii Text
    strXMLRequest = BytesToText(Request.BinaryRead(Request.TotalBytes))
    
    xmlDoc.async = False
    xmlDoc.LoadXML strXMLRequest
    
    GenerateErrorResponse  'Check for any errors
    
    'Retrieve the various paramaters that will be written to the database
    strDivisionNbr = xmlDoc.documentElement.selectsinglenode("DIVISION_NBR").text
    strAccountNbr = xmlDoc.documentElement.selectsinglenode("ACCOUNT_NBR").text
    strUserName = xmlDoc.documentElement.selectsinglenode("USER_RACF").text
    strDomainName = xmlDoc.documentElement.selectsinglenode("DOMAIN_NAME").text
    strMachineName = xmlDoc.documentElement.selectsinglenode("MACHINE_NAME").text
    strRequest = xmlDoc.documentElement.selectsinglenode("REQUEST").text
    strResponseCode = xmlDoc.documentElement.selectsinglenode("RESPONSE_CODE").text
    strOperatorID = xmlDoc.documentElement.selectsinglenode("OPERATOR_ID").text
    strRegions = xmlDoc.documentElement.selectsinglenode("REGIONS").text
    strPurgeDate = xmlDoc.documentElement.selectsinglenode("PURGE_DATE").text
    strStatus = xmlDoc.documentElement.selectsinglenode("STATUS").text
    strAssociateId = xmlDoc.documentElement.selectsinglenode("ASSOCIATE_ID").text
    
    GenerateErrorResponse  'Check for any errors
    
    'Establish connection to the SQL Database
    strUserID = "***"
    strPassword = "***"
    strConnectionString = "Provider=SQLOLEDB; Data Source=***; Initial Catalog=***"
    objConnection.Open strConnectionString, strUserID, strPassword 
    
    'Create and populate the paramaters collection 
    With objCommand
    	.Parameters.Append .CreateParameter("AssociateId", adVarChar, adParamInput, 8, strAssociateId )
    	.Parameters.Append .CreateParameter("Operator", adChar, adParamInput, 3, strOperatorID)
    	.Parameters.Append .CreateParameter("Division", adInteger, adParamInput, , CInt(strDivisionNbr))
    	.Parameters.Append .CreateParameter("Account", adVarChar, adParamInput, 32, strAccountNbr)
    	.Parameters.Append .CreateParameter("Domain", adVarChar, adParamInput, 30, strDomainName)
    	.Parameters.Append .CreateParameter("MachineName", adVarChar, adParamInput, 30, strMachineName)
    	.Parameters.Append .CreateParameter("Region", adChar, adParamInput, 1, strRegions)
    	.Parameters.Append .CreateParameter("Request", adChar, adParamInput, 2, strRequest)
    	.Parameters.Append .CreateParameter("Response", adChar, adParamInput, 2, strResponseCode)
    	.Parameters.Append .CreateParameter("Date", adDate, adParamInput, , CDate(strPurgeDate))
    	.Parameters.Append .CreateParameter("Status", adVarChar, adParamInput, 100, strStatus)
    	.Parameters.Append .CreateParameter("UserName", adVarChar, adParamInput, 8, strUserName)
    	
    	 'Initialize and execute the stored procedure
    	.ActiveConnection = objConnection
    	.CommandText = "p_Add_MPS"
    	.CommandType = adCmdStoredProc
    	.Execute
    End With
    
    GenerateErrorResponse  'Check for any errors
    
    'Build Xml Response Document
    xmlResponseDoc.appendChild xmlResponseDoc.createElement("UPDATE_MPS_STATUS_SCREEN_RESP")
    xmlResponseDoc.documentElement.appendChild xmlResponseDoc.createElement("SUCCESS")
    Response.Write xmlResponseDoc.xml  'Write Out the Response Xml
    Response.End 
    
    'This routine grabs the specified value from the node, and if it is empty, return a null string
    Function SetValue(xmlRoot, strTagName)
        Dim xmlNodeList
        
        Set xmlNodeList = xmlRoot.getElementsByTagName(strTagName)
        If xmlNodeList.length > 0 Then
            SetValue = xmlRoot.selectSingleNode("//" & strTagName).Text
        Else
            SetValue = ""
        End If    
        Set xmlNodeList = Nothing
    End Function
    
    'Read the byte stream in from the request object, then convert it to its ascii form
    Function BytesToText(strBytes)    	
    	Dim lngLength
        Dim lngIndex
        Dim lngAsciiCode
        Dim strAsciiText    
    	
        lngLength = LenB(strBytes)    	
        For lngIndex = 1 To lngLength
        	lngAsciiCode = AscB(MidB(strBytes, lngIndex, 1))
        	strAsciiText = strAsciiText & Chr(lngAsciiCode)
        Next
        	
        BytesToText = strAsciiText
    End Function
    
    'Generate Xml Error Response if an error occurs
    Sub GenerateErrorResponse()
    	If Not Err.number = 0 then		
    		Set xmlErrorDoc = CreateObject("Microsoft.XMLDOM")		
    		xmlErrorDoc.appendChild xmlErrorDoc.createElement("UPDATE_MPS_STATUS_SCREEN_RESP")
    		xmlErrorDoc.documentElement.appendChild( xmlErrorDoc.createElement("ERROR")).Text =	Err.description 	
    		Response.Write xmlErrorDoc.xml
    		Response.End
    	End if
    End Sub
    %>

  9. #9

    Thread Starter
    Member
    Join Date
    Nov 2002
    Posts
    32

    THANXALOT!

    THANXALOT!

  10. #10
    Addicted Member
    Join Date
    Oct 2002
    Posts
    241
    w3schools.com has a great web service tutorial and some good examples too.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width