calling .net webservice from vbscript

Author Message
collie

  • Total Posts : 11
  • Scores: 0
  • Reward points : 0
  • Joined: 2/11/2008
  • Status: offline
calling .net webservice from vbscript Thursday, December 04, 2008 2:54 AM (permalink)
0
Hi,
 
I need to call a .net webservice from classic asp.
The webservice
 
I wrote the function using get and it works. However, I am having problems writing it using post method.
can someone please help?
 
Here is my code using get method:
  
 Function consumeWebService() 
    
     Dim webServiceUrl, httpReq, node, myXmlDoc, param 
   
 webServiceUrl ="http://xxxxxx/SSO_WS/SSOWS.asmx/GetSessionIdentifier?userId=test&xml=<?xml version='1.0' encoding='utf-8' ?><User><Name>todd@test.com</Name><Profile>4</Profile></User>&appName=kb"
 
        dim responseXML
  Set responseXML = CreateObject("Microsoft.XMLDOM") 
  Set objServerXML = CreateObject("MSXML2.ServerXMLHTTP.3.0")
  responseXML.async = False
  objServerXML.setTimeouts 120*1000,120*1000,5*60*1000,60*60*1000
  With objServerXML
  Call .open("GET", webServiceUrl , False)
  Call .send'(strXMLInput)
  SendViaXML = Stream_BinaryToString(objServerXML.responseBody, "UTF-8")
  End With
  responseXML.loadXML(SendViaXML)
  
  
 dim xmlstring, xmldoc
 
  set xmldoc=Server.CreateObject("Microsoft.XMLDOM")'
 
  xmldoc.loadXML responseXML.documentElement.Text
  
  'set node = nothing
  set nodeCode = xmldoc.selectSingleNode("/Result/Code")
 
  if nodeCode is nothing then
  response.write "Could not find node"
  else
  if nodeCode.text=0 then
  set nodeData = xmldoc.selectSingleNode("/Result/Data")
  sessionid=(nodeData.text)
  end if
  end if
 
       consumeWebService= sessionid
 End Function
 

 
#1
    TNO

    • Total Posts : 2094
    • Scores: 36
    • Reward points : 0
    • Joined: 12/18/2004
    • Location: Earth
    • Status: offline
    RE: calling .net webservice from vbscript Thursday, December 04, 2008 4:15 AM (permalink)
    0
    escape the XML before you stick it in the url

    use the "POST" argument in the Open Method

    you also need to specify the appropriate Content-Type or the server will reject your POST

    .setRequestHeader"Content-Type","application/x-www-form-urlencoded;charset=UTF-8")
    .setRequestHeader("Content-length", Length of your data)
    .setRequestHeader("Connection", "close")
    To iterate is human, to recurse divine. -- L. Peter Deutsch
     
    #2
      TNO

      • Total Posts : 2094
      • Scores: 36
      • Reward points : 0
      • Joined: 12/18/2004
      • Location: Earth
      • Status: offline
      RE: calling .net webservice from vbscript Thursday, December 04, 2008 4:37 AM (permalink)
      0
      I didnt see this before, but if you are using POST. take the data off of the url and put it in the Send method
      To iterate is human, to recurse divine. -- L. Peter Deutsch
       
      #3

        Online Bookmarks Sharing: Share/Bookmark

        Jump to:

        Current active users

        There are 0 members and 1 guests.

        Icon Legend and Permission

        • New Messages
        • No New Messages
        • Hot Topic w/ New Messages
        • Hot Topic w/o New Messages
        • Locked w/ New Messages
        • Locked w/o New Messages
        • Read Message
        • Post New Thread
        • Reply to message
        • Post New Poll
        • Submit Vote
        • Post reward post
        • Delete my own posts
        • Delete my own threads
        • Rate post

        2000-2012 ASPPlayground.NET Forum Version 3.9