Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / May 2006

Tip: Looking for answers? Try searching our database.

passing complex data types with vbscript?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
greg@apba.net - 26 May 2006 21:09 GMT
We have a set of .NET web services to provide access to our data.  They
use complex data types for both incoming data and return data.  We are
attempting to help another group access this web service from
vbscript/ASP.  Is this possible?  I have found a few posts scattered
around the internet saying complex data types aren't possible with
vbscript.

Is this true?  Can I manually create my XML document in the vbscript,
pass it to the web service, then manually deconstruct the return XML?

Thanks,
Greg
Kirk Allen Evans - 27 May 2006 03:17 GMT
Absolutely, it's possible.  Here's the web service:

using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService
{
   [WebMethod]
   public string HelloWorld(PhoneNumber tn)
   {
       return "Phone number is: (" + tn.NPA + ")" + tn.NXX + "-" + tn.Line;
   }
}

public class PhoneNumber
{
   private string _npa;
   private string _nxx;
   private string _line;

   public PhoneNumber()
   {
   }

   public PhoneNumber(string npa, string nxx, string line)
   {
       _npa = npa;
       _nxx = nxx;
       _line = line;
   }

   public string NPA
   {
       get { return _npa; }
       set { _npa = value; }
   }
   public string NXX
   {
       get { return _nxx; }
       set { _nxx = value; }
   }

   public string Line
   {
       get { return _line; }
       set { _line = value; }
   }
}

The following uses JavaScript to call the web service, but the same exact
steps would apply for VBScript.  You can concatenate a string, or you can
use the DOM model (more information at
http://support.microsoft.com/kb/893659/).

The following is an HTML file, no ASP.NET or anything involved here (nothing
but client code).

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
   <title>Untitled Page</title>
</head>
<body>
<script language="javascript">
   function CallWS(npa, nxx, line)
   {
       var x;
       x = new ActiveXObject("Microsoft.XMLHTTP");

       var envelope;
       envelope = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
               "<soap:Envelope
xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
                   "<soap:Body>" +
                       "<HelloWorld xmlns=\"http://tempuri.org/\">" +
                       "<tn>" +
                           "<NPA>" + npa + "</NPA>" +
                           "<NXX>" + nxx + "</NXX>" +
                           "<Line>" + line + "</Line>" +
                       "</tn>" +
                        "</HelloWorld>" +
                    "</soap:Body>" +
               "</soap:Envelope>";
            // send the POST to the Web service
    x.open("POST", "http://localhost:8080/WebSite2/WebService.asmx",
false);
    x.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    x.setRequestHeader("SOAPAction", "http://tempuri.org/HelloWorld");
    x.send(envelope);
    alert(x.responseText);
   }
</script>

<button onclick="CallWS('404','555','1212');return false;" />
</body>
</html>

Kirk Allen Evans
Developer Evangelist
Microsoft Corporation
blogs.msdn.com/kaevans
> We have a set of .NET web services to provide access to our data.  They
> use complex data types for both incoming data and return data.  We are
[quoted text clipped - 8 lines]
> Thanks,
> Greg
Gaurav Vaish (EduJini.IN) - 27 May 2006 14:37 GMT
> Absolutely, it's possible.  Here's the web service:

> public class PhoneNumber
>    public string NPA

Probably a perfect example given by Kirk.
My 2cents...

You may want to look into the topic of XML Serialization and custom
attributes in case you have a really complex structure of data possibly with
arrays.

Signature

Happy Hacking,
Gaurav Vaish
http://www.mastergaurav.org
http://www.edujini.in
-------------------

greg@apba.net - 27 May 2006 23:06 GMT
Thanks for the replies.  I hadn't mentioned that it was a SOAP web
service, so I'm glad you included that in your example.

It looks like I will need to construct my SOAP message and body
manually, which is fine.

Thanks for the tip on XML Serialization, I'll look into that also.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.