1

Does anyone have any good examples of calling a WCF service from a classic asp page? I looked at

Calling REST web services from a classic asp page [closed]

and it got me closer but I need to pass parameters to the service and I'm not sure how to do that with a wcf? Currently I'm just getting back the wsdl.

2 Answers 2

2

The best way to do this will be to create a class in C# or VB.NET. This class will expose its public methods as a COM object. All the class will do is to call the web service and return the results.

You'll then be able to use this COM object from Classic ASP, which will have no idea that it's in touch with the 21st Century.

BTW, this is a good way to refactor functionality out of VBSCRIPT and into the modern world of .NET - do it one COM object at a time. Later, if you ever want to convert pages to ASP.NET (or its successor ten years from now), you'll at least have all the busineess logic factored out, and ASP.NET will be able to call it.

0
1

You can also use the MSXML2.ServerXMLHTTP object to make calls in asp. Here's an example of me calling one of my services and sending a json payload.

<script language="javascript" runat="server" src="/engine/includes/json2.js"></script>

<%
    DIM xmlhttp, response, objRequest, txtRequest, test
    DIM url : url = "https://myservice.com/Service.svc/json/Test"

    SET objRequest = JSON.parse("{}")
    objRequest.set "param1", "echo this text"

    set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")

    xmlhttp.setOption 2, 13056   'ignore certificate errors for development machines
    xmlhttp.open "POST", url, false
    xmlhttp.setRequestHeader "Content-Type", "application/json"
    txtRequest = JSON.stringify(objRequest)
    xmlhttp.send txtRequest
    response = xmlhttp.responseText
    Response.Write response
%>

For the JSON parsing I'm using DouglasCrockford's library - https://github.com/douglascrockford/JSON-js/blob/master/json2.js

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.