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 / General / July 2007

Tip: Looking for answers? Try searching our database.

I'm at my wit's end--beginner to VS 2005, long-standing VB6 programmer

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brent White - 17 Jul 2007 16:04 GMT
The documentation provided by the people here has been somewhat
helpful, but it appears I am missing the boat somewhere.

I have a web service I designed in VS 2005 that right now is doing
nothing more than returning an XML stream to a client.  Eventually, it
will post an HTTP request to an outside server, but I'm trying to
learn VS 2005 as I go so I'm right now trying just to get a web
service to post to and it posts back what you post to it through
SOAP.  This is the code:

Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel

<System.Web.Services.WebService(Namespace:="http://badger.com/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)>
_
<ToolboxItem(False)> _
Public Class Service1
   Inherits System.Web.Services.WebService

   <WebMethod()> _
   Public Function AuthorizeAPI(ByVal Input1 As InformationToPass) As
ReturnParams
       Dim rp As New ReturnParams
       'Return "Hi, this page is served by Brent White's own system
and can be looked at " & Input1.SecondParam & " times."
       'Return Input1.SerialNumber
       'Return Input1.Dev_SerialNumber
       rp.SJName = Input1.SJName
       rp.Email = Input1.Email
       'Return Input1.BillStreet
       'Return Input1.BillStreet2
       'Return Input1.BillStreet3
       'Return Input1.BillStreet4
       'Return Input1.BillCity
       'Return Input1.BillState
       'Return Input1.BillZip
       'Return Input1.BillCountry
       'Return Input1.BillPhone
       'Return Input1.BillFax
       'Return Input1.ShipName
       'Return Input1.ShipStreet
       'Return Input1.ShipStreet2
       'Return Input1.ShipStreet3
       'Return Input1.ShipStreet4
       'Return Input1.ShipCity
       'Return Input1.ShipState
       'Return Input1.ShipZip
       'Return Input1.ShipCountry
       'Return Input1.ShipPhone
       'Return Input1.ShipFax
       'Return Input1.AccountNumber
       'Return Input1.MonthExpr
       'Return Input1.YearExpr
       'Return Input1.CVV2
       'Return Input1.TransactionAmount
       'Return Input1.SalesTax
       'Return Input1.CustomerCode
       'Return Input1.PONumber
       'Return Input1.ShippingAmount
       'Return Input1.SummaryCommodityCode
       'Return Input1.OrderString_lvl3
       Return rp
   End Function

End Class

Public Class InformationToPass
   Public SerialNumber As String = "000399239784"
   Public Dev_SerialNumber As String = "100008901765"
   Public SJName As String
   Public Email As String
   Public BillStreet As String
   Public BillStreet2 As String
   Public BillStreet3 As String
   Public BillStreet4 As String
   Public BillCity As String
   Public BillState As String
   Public BillZip As String
   Public BillCountry As String
   Public BillPhone As String
   Public BillFax As String
   Public ShipName As String
   Public ShipStreet As String
   Public ShipStreet2 As String
   Public ShipStreet3 As String
   Public ShipStreet4 As String
   Public ShipCity As String
   Public ShipState As String
   Public ShipZip As String
   Public ShipCountry As String
   Public ShipPhone As String
   Public ShipFax As String
   Public OrderNumber As String
   Public AccountNumber As String
   Public MonthExpr As String
   Public YearExpr As String
   Public CVV2 As String
   Public TransactionAmount As String
   Public SalesTax As String
   Public CustomerCode As String
   Public PONumber As String
   Public ShippingAmount As String
   Public SummaryCommodityCode As String
   Public OrderString_lvl3 As String
End Class

Public Class ReturnParams
   Public SJName As String
   Public Email As String
End Class

web.config:

<?xml version="1.0"?>

<configuration>

   <configSections>
       <sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGroup, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
           <section name="Testing.My.MySettings"
type="System.Configuration.ClientSettingsSection, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
       </sectionGroup>
   </configSections>
   <appSettings/>
   <connectionStrings/>

   <system.web>
       <!--
           Set compilation debug="true" to insert debugging
           symbols into the compiled page. Because this
           affects performance, set this value to true only
           during development.

           Visual Basic options:
           Set strict="true" to disallow all data type conversions
           where data loss can occur.
           Set explicit="true" to force declaration of all variables.
       -->
       <compilation debug="true" strict="false" explicit="true" />
       <pages>
           <namespaces>
               <clear />
               <add namespace="System" />
               <add namespace="System.Collections" />
               <add namespace="System.Collections.Specialized" />
               <add namespace="System.Configuration" />
               <add namespace="System.Text" />
               <add namespace="System.Text.RegularExpressions" />
               <add namespace="System.Web" />
               <add namespace="System.Web.Caching" />
               <add namespace="System.Web.SessionState" />
               <add namespace="System.Web.Security" />
               <add namespace="System.Web.Profile" />
               <add namespace="System.Web.UI" />
               <add namespace="System.Web.UI.WebControls" />
               <add namespace="System.Web.UI.WebControls.WebParts" />
               <add namespace="System.Web.UI.HtmlControls" />
           </namespaces>
       </pages>
       <!--
           The <authentication> section enables configuration
           of the security authentication mode used by
           ASP.NET to identify an incoming user.
       -->
       <!--
           The <customErrors> section enables configuration
           of what to do if/when an unhandled error occurs
           during the execution of a request. Specifically,
           it enables developers to configure html error pages
           to be displayed in place of a error stack trace.

       <customErrors mode="RemoteOnly"
defaultRedirect="GenericErrorPage.htm">
           <error statusCode="403" redirect="NoAccess.htm" />
           <error statusCode="404" redirect="FileNotFound.htm" />
       </customErrors>
       -->
     <webServices>
       <protocols>
         <add name="HttpGet"/>
         <add name="HttpPost"/>
         <add name="HttpSoap"/>
       </protocols>
     </webServices>

   </system.web>
   <applicationSettings>
       <Testing.My.MySettings>
           <setting name="Testing_localhost_Service1"
serializeAs="String">
               <value>http://localhost/Service1.asmx</value>
           </setting>
       </Testing.My.MySettings>
   </applicationSettings>
</configuration>

And this is the VB code that forms the client:

Imports System.IO
Imports System.Xml

Module Module1

   Sub Main()
       Dim msg As String
       Dim strm As Stream
       Dim strmrdr As System.IO.StreamReader
       Dim http As New MSXML2.XMLHTTP30
       Dim serviceurl As String = "http://localhost/Service1.asmx"
       msg = "<soap:Envelope "
       msg = msg & "xmlns:xsi='http://www.w3.org/2001/XMLSchema-
instance'"
       msg = msg & "xmlns:xsi='http://www.w3.org/2001/XMLSchema'"
       msg = msg & "xmlns:soap='http://schemas.xmlsoap.org/soap/
envelope'>"
       msg = msg & "<soap:Body>"
       msg = msg & "<AuthorizeAPI xmlns='http://badger.com'>"
       msg = msg & "<Input1>"
       msg = msg & "<SJName>Me</SJName>"
       msg = msg & "<Email>brent_white@roadrunner.com</Email>"
       msg = msg & "</Input1>"
       msg = msg & "</AuthorizeAPI>"
       msg = msg & "</Soap:Body>"
       msg = msg & "</Soap:Envelope>"

       http.open("POST", serviceurl, False)
       http.setRequestHeader("SOAPACTION", """http://badger.com/
AuthorizeAPI""")
       http.setRequestHeader("Content-Type", "text/xml")
       http.send(msg)
       Console.Write(http.responseStream.ToString)
       strm = http.responseStream
       strmrdr = New StreamReader(strm)
       'Dim xmlreader As New XmlTextReader(strm)
       'Do While (xmlreader.Read())
       ' Select Case XmlReader.NodeType
       '     Case XmlNodeType.Element
       ' Console.Write("<" + XmlReader.Name)
       ' If XmlReader.HasAttributes Then 'If attributes exist
       ' While XmlReader.MoveToNextAttribute()
       ' 'Display attribute name and value.
       ' Console.Write(" {0}='{1}'", XmlReader.Name, XmlReader.Value)
       'End While
       'End If
       'Console.WriteLine(">")
       '    Case XmlNodeType.Text 'Display the text in each element.
       'Console.WriteLine(XmlReader.Value)
       '    Case XmlNodeType.EndElement 'Display end of element.
       'Console.Write("</" + XmlReader.Name)
       'Console.WriteLine(">")
       'End Select
       'Loop
       '        MsgBox(msg)
       'Console.Write(msg)
       Console.ReadKey()

   End Sub

End Module

First, I get a message on the console:  System.__ComObject

And I get a runtime error:

Unable to cast COM object of type 'System.__ComObject' to class type
'System.IO.Stream'. Instances of types that represent COM components
cannot be cast to types that do not represent COM components; however
they can be cast to interfaces as long as the underlying COM component
supports QueryInterface calls for the IID of the interface.

What I want to do is pull the response into a stream reader so I can
make sure what I'm getting from the web service is what I am expecting.
Cowboy (Gregory A. Beamer) - 17 Jul 2007 17:05 GMT
Set up the object you are passing back first.
Then, set up the service.
Then, test the service, something like this (apologies for the C#, but I am
not coding VB at the moment and do not want to screw up my momentum)

[WebMethod]
public MyObject GetObject(int objectID)
{
   return new MyObject(objectID);
}

If you want to stub a test, create a constructor that "fills" the object
with garbage no matter what objectID is passed to the constructor.

Open the web service in IE. test it. Did you get back XML with the values
you expected? If so, you have already created a proper web service.

The next issue is getting the information from another "service" that does
not operate according to standards (your HTTP Request). Separate that issue
from getting the web service to work and you will be much saner. They are
two separate issues.

Signature

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
Co-author: Microsoft Expression Web Bible (upcoming)

************************************************
Think outside the box!
************************************************

> The documentation provided by the people here has been somewhat
> helpful, but it appears I am missing the boat somewhere.
[quoted text clipped - 274 lines]
> What I want to do is pull the response into a stream reader so I can
> make sure what I'm getting from the web service is what I am expecting.
Brent White - 18 Jul 2007 16:18 GMT
What object am I setting up and is someone around who knows VB.NET?

> Set up the object you are passing back first.
> Then, set up the service.
[quoted text clipped - 283 lines]
> >
> > End Module

Rate this thread:







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.