locked
Using WCF Service Methods in classic ASP. RRS feed

  • Question

  • Hi All,

    I want to consume the methods exposed by WCF Service from my classic asp application. I have written a console application
    where I have created "ServiceReference" and compiled the console application. I have used the .dll's of this console application
    and created ".tlb" file using using RegAsm of .Net 2.0 and now I am trying to register this .tlb file in COM Component. But here
    I could not see the methods exposed by console application and could not go to next step as "Next" button is disabled.

    I think using .NET Framework RegAsm for creating .NET 3.5 solution is creating the problem but I am not sure.

    Can any one help me out from here.

    Thanks.

     

    Tuesday, June 15, 2010 7:17 AM

Answers

  • Hi lkdhage,

    If you want to use generated client proxy to call WCF service, I suggest you try putting all the configuration (like the binding and endpoint) into code(instead of using app.config file) since classic ASP client is not .NET based and it is not quite convenient to provide a config file for it.

    #How to: Programmatically Configure a WCF Endpoint
    http://msdn.microsoft.com/en-us/library/ff647110.aspx

    #WCF Essentials—Programmatic Client Configuration
    http://en.csharp-online.net/WCF_Essentials%E2%80%94Programmatic_Client_Configuration

    After you've encapsulated all the client proxy and configuration into code, you can just build a single .NET dll and expose it as COM object(through regasm) and use it in your ASP page.

    another option is that if your WCF service can be developed as REST style, you can use any HTTP GET/POST enabled component like the COM XMLHTTP or XMLServerHttp component to consume the WCF REST service.

    #Using the XML HTTP Request object
    http://www.jibbering.com/2002/4/httprequest.html


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Monday, June 21, 2010 9:34 AM

All replies

  • Can any one please provide help for the above problem.

    Thanks

    Tuesday, June 15, 2010 10:42 AM
  • Hi lkdhage,

    If you want to use generated client proxy to call WCF service, I suggest you try putting all the configuration (like the binding and endpoint) into code(instead of using app.config file) since classic ASP client is not .NET based and it is not quite convenient to provide a config file for it.

    #How to: Programmatically Configure a WCF Endpoint
    http://msdn.microsoft.com/en-us/library/ff647110.aspx

    #WCF Essentials—Programmatic Client Configuration
    http://en.csharp-online.net/WCF_Essentials%E2%80%94Programmatic_Client_Configuration

    After you've encapsulated all the client proxy and configuration into code, you can just build a single .NET dll and expose it as COM object(through regasm) and use it in your ASP page.

    another option is that if your WCF service can be developed as REST style, you can use any HTTP GET/POST enabled component like the COM XMLHTTP or XMLServerHttp component to consume the WCF REST service.

    #Using the XML HTTP Request object
    http://www.jibbering.com/2002/4/httprequest.html


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Monday, June 21, 2010 9:34 AM
  • Steven, hi. I´m new with WCF. I followed a lot of posted examples & tutorials even the ones you posted. I managed to build the service and the client. As Ikdage, I too have a clasic ASP web application that uses .net dlls to comunicate with a .net service. The pages and the .net dlls wich are expose to COM through regasm are in server "A" and the service is in server "B". When I run the site from within server "A" with an IE, all works fine, but when i do the same from my machine ("http://serverA/site"), it hangs up resuming in a timeout exception. I can not find the root of the exception. Can you give me some advice? up to what is see, the channelfactory in the client is created but it crashes when trying to use a service method.

    This is my code:

    Service:

    <ServiceModel.ServiceContract()> Public Interface IConnXPool

     

    <OperationContract()> Function Execute(ByVal SQL As String, ByVal Agent As String, ByVal System As String, Optional ByVal Procedure As String = "") As System.Data.DataSet

     

    '<OperationContract()> Function ExecuteWOP(ByVal SQL As String, ByVal System As String, Optional ByVal Procedure As String = "") As Object

     

    <OperationContract()> Sub RefreshConnections()

     

    <OperationContract()> Function GetParam(ByVal ParamName As String, Optional ByVal System As String = "", Optional ByVal Procedure As String = "") As String

     

    <OperationContract()> Function AllConnAreUP() As Boolean

     

    <OperationContract()> Function QtyConnAreUP() As Long

     

    <OperationContract()> Function QtyConnWithOutPool() As Long

     

    <OperationContract()> Sub Log(ByVal pvar_Message As String, Optional ByVal pvar_MessageType As System.Diagnostics.EventLogEntryType = EventLogEntryType.Information)

     

    End Interface

    Private Sub Iniciar()

    _LogLevel = CInt(GetRegistryParameter("LogLevel"))

    _LogSw = CInt(GetRegistryParameter("LogSw"))

    _LogPath = GetRegistryParameter("LogPath")

    Try

    Dim lvar_PoolPort As String = GetRegistryParameter("PoolPort")

    Dim lvar_ChannelTimeOut As Double

    Dim lvar_baseAddress As String = "net.tcp://localhost:" + lvar_PoolPort + "/ConnXPool"

     

    If Double.TryParse(GetRegistryParameter("ChannelTimeOut"), lvar_ChannelTimeOut) = False Then lvar_ChannelTimeOut = 10

     

    _ConnectionRefresh = CInt(GetRegistryParameter("ConnectionRefresh"))

    server = New ConnXPool

     

    mobj_ServiceHost = New ServiceHost(server, New Uri(lvar_baseAddress))

    mobj_ServiceHost.Description.Name = "IConnXPool"

     

    Dim lobj_TcpBinding As New NetTcpBinding()

    Dim lobj_TimeOut As New System.TimeSpan

    Dim lobj_ServiceEndPoint As ServiceEndpoint

    Dim lobj_BehaviorAttribute As ServiceBehaviorAttribute

    Dim lobj_ThrottlingBehavior As ServiceThrottlingBehavior

     

    lobj_TimeOut = System.TimeSpan.FromMinutes(10)

    lobj_TcpBinding.OpenTimeout = lobj_TimeOut

    lobj_TcpBinding.CloseTimeout = lobj_TimeOut

    lobj_TcpBinding.SendTimeout = lobj_TimeOut

    lobj_TcpBinding.ReceiveTimeout = lobj_TimeOut

     

    lobj_TcpBinding.MaxBufferSize = 6553600

    lobj_TcpBinding.MaxReceivedMessageSize = 6553600

     

    lobj_TcpBinding.ReliableSession.Enabled = True

    lobj_ServiceEndPoint = mobj_ServiceHost.AddServiceEndpoint(GetType(IConnXPool), lobj_TcpBinding, lvar_baseAddress)

    lobj_ServiceEndPoint.Contract.Name = "IConnXPool"

     

    lobj_BehaviorAttribute = mobj_ServiceHost.Description.Behaviors.Find(Of ServiceBehaviorAttribute)()

    If IsNothing(lobj_BehaviorAttribute) = True Then

    lobj_BehaviorAttribute = New ServiceBehaviorAttribute()

    mobj_ServiceHost.Description.Behaviors.Add(lobj_BehaviorAttribute)

    End If

    lobj_BehaviorAttribute.ConcurrencyMode = ConcurrencyMode.Multiple

    lobj_BehaviorAttribute.IncludeExceptionDetailInFaults = True

    lobj_BehaviorAttribute.InstanceContextMode = InstanceContextMode.Single

    lobj_BehaviorAttribute.SetWellKnownSingleton(server)

    lobj_BehaviorAttribute.TransactionTimeout = lobj_TimeOut.ToString

    lobj_BehaviorAttribute.ValidateMustUnderstand = False

    lobj_BehaviorAttribute.TransactionIsolationLevel = System.Transactions.IsolationLevel.Serializable

    lobj_BehaviorAttribute.ReleaseServiceInstanceOnTransactionComplete = False

     

    lobj_ThrottlingBehavior = mobj_ServiceHost.Description.Behaviors.Find(Of ServiceThrottlingBehavior)()

    If IsNothing(lobj_ThrottlingBehavior) = True Then

    lobj_ThrottlingBehavior = New ServiceThrottlingBehavior()

    mobj_ServiceHost.Description.Behaviors.Add(lobj_ThrottlingBehavior)

    End If

    lobj_ThrottlingBehavior.MaxConcurrentCalls = Integer.MaxValue

    lobj_ThrottlingBehavior.MaxConcurrentInstances = Integer.MaxValue

    lobj_ThrottlingBehavior.MaxConcurrentSessions = Integer.MaxValue

     

    mobj_ServiceHost.CloseTimeout = lobj_TimeOut

    mobj_ServiceHost.OpenTimeout = lobj_TimeOut

    mobj_ServiceHost.Open()

    Catch ex As Exception

    LogearEvento(_LogLevel, _LogSw, _LogPath, ex.Message, EventLogEntryType.Error)

    End Try

    End Sub

     

    Client:

    Private Sub DoSomething()

    _sPoolServer = GetRegistryParameter("PoolServer")

    _sPoolPort = GetRegistryParameter("PoolPort")

    Dim lobj_TcpBinding As New NetTcpBinding()

    Dim lvar_baseAddress As String = "net.tcp://" + _sPoolServer + ":" + _sPoolPort + "/ConnXPool"

    Dim lobj_ServiceEndPointAdress As New EndpointAddress(lvar_baseAddress)

     

    lobj_TcpBinding.SendTimeout = System.TimeSpan.FromMinutes(10)

    lobj_TcpBinding.MaxBufferSize = 6553600

    lobj_TcpBinding.MaxReceivedMessageSize = 6553600

    lobj_TcpBinding.ReliableSession.Enabled = True

     

    Dim lobj_ChannelFactory As New ChannelFactory(Of IConnXPool)(lobj_TcpBinding, lobj_ServiceEndPointAdress)

     

    lobj_ChannelFactory.Endpoint.Contract.Name = "IConnXPool"

    lobj_ChannelFactory.Open()

     

    _IConnXPool = lobj_ChannelFactory.CreateChannel()

     

    _IConnXPool.getClientCode("Gonzalo")

    End Sub

     

    Many thxs.

    Thursday, July 15, 2010 6:58 PM
  • Please where you read "_IConnXPool.getClientCode("Gonzalo")" show say:

    dim a as long=_IConnXPool.QtyConnAreUP()


    Thursday, July 15, 2010 7:00 PM
  • Can anyone please help me with my problem? Many thanks in advanced
    Tuesday, July 20, 2010 12:23 AM
  • Hi I am following the link 10-14 section of http://msdn.microsoft.com/en-us/library/bb735856.aspx article. I am using wsHttpBinding in wcf. When I try accessing the the asp page I am getting the followin error.

     

    Error:

    error '80131522'

    /MyProject/test.asp, line 11

     

    Code of test.asp

    <%
    Dim quoteProxy, wsdl, moniker, result
    wsdl = GetWsdlFromUrl ("http://<<machine name where wcf service is hosted>>/Samplewcf/Service.svc?wsdl" )
    moniker="service:wsdl=" & wsdl & ", "
    moniker=moniker + "address=http://<<machine name where wcf service is hosted>>/Samplewcf/Service.svc,"
    moniker=moniker + "contract=IService, "
    moniker=moniker + "contractNamespace=http://tempuri.org/, "
    moniker=moniker + "binding=wsHttpBinding_IService, "
    moniker=moniker + "bindingNamespace=http://tempuri.org/"
    Set quoteProxy = GetObject(moniker)
    result = quoteProxy.GetData(25)
    Response.Write result
    Function GetWsdlFromUrl( strUrl )
    Dim WinHttpReq, resp
    Set WinHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")
    resp = WinHttpReq.Open("GET", strUrl, False)
    WinHttpReq.Send()
    GetWsdlFromUrl = WinHttpReq.ResponseText
    End Function
    %>

    Here line 11 is

    result = quoteProxy.GetData(25)

    Can any one help me plz. I am struck here completely.

    Thanks in Advance.

     

    Thursday, July 22, 2010 11:10 AM
  • Hi All,

    I have downloaded the sample solution given in http://code.msdn.microsoft.com/CallWCFfromASP and I am able to access WCF methods when the binding is "basicHttpBinding". When I change the binding to "wsHttpBinding" and try to access the WCF methods I get the following error.

    About to call WCF Web Service from Classic ASP...
    Finished calling Web Service.
    Status = Bad Request
    ResponseText =

    Code:

    soapServer = "http://<servername>/Samplewcf/Service.svc"

    soapMessage = "<s:Envelope xmlns:s="&chr(34)&"http://schemas.xmlsoap.org/soap/envelope/"&chr(34)&">" & _

    "<s:Body>" & _

    "<GetData xmlns="&chr(34)&"http://tempuri.org/"&chr(34)&"><value>25</value></GetData>" & _

    "</s:Body>" & _

    "</s:Envelope>"

    soapMessage = Replace(soapMessage, "'", chr(34))

    Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")

    xmlhttp.open "POST", soapServer, False

    xmlhttp.setRequestHeader "Man", POST & " " & soapServer & " HTTP/1.1"

    xmlhttp.setRequestHeader "SOAPAction", "http://tempuri.org/IService/GetData"

    xmlhttp.setRequestHeader "Content-Type", "application/soap+xml; charset=utf-8"

    Response.Write "About to call WCF Web Service from Classic ASP..."

    xmlhttp.send(soapMessage)

    Can any one help me.

     

    Thanks in Advance

    lkdhage

    Tuesday, July 27, 2010 7:08 AM