Alas...trying to get a web service response from a web service that is part of the web site in Visual Studio.Net 3.5 appears to be impossible. Infact, I've been ALL over the internet over the past couple of days looking at all types of fragmentory examples in all types of Microsoft languages to no avail.
=========
QUESTION:
=========
1. How do I call a web service (the function to call is "WebService_BulkData") so that my aspx page will send it a SOAP request and print out the web service response data to the page? The aspx page AND the web service are part of the SAME web site project. The web site project is being developed on a beta server (not locally stored on a computer and then uploaded).Man, that sure sounds simple, doesn't it?
=======================================================
Here is the latest code-behind page_load() for the default.aspx page which calls the web service, gets its response and then just dumps it to the page so it can be determined that we are getting somewhere:
=======================================================
Dim objRequest As WebRequest = HttpWebRequest.Create("http://betasite.com/WebService_BulkData.asmx")
Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")
Dim soapBody As String = ""
soapBody = "<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">"
soapBody = "<soap:Body>"
soapBody = "<XMLServiceData xmlns=""http://betasite.com"" />"
soapBody = "</soap:Body>"
soapBody = "</soap:Envelope>"
objRequest.Method = "POST"
objRequest.ContentType = "text/xml; charset=utf-8"
objRequest.ContentLength = soapBody.Length
objRequest.Headers.Add("SOAPAction", "XMLServiceData")Dim myRequest As System.IO.StreamWriter = New System.IO.StreamWriter(objRequest.GetRequestStream())
myRequest.Write(soapBody)
myRequest.Close() ' App hangs if close is not here' 500 Error is generated when viewing default.aspx in browser at the following line. Why? Not even sure if this is the best way.
Dim webResponse As System.IO.StreamReader = New System.IO.StreamReader(objRequest.GetResponse().GetResponseStream())
Dim receiveStream As String = ""
While Not webResponse.EndOfStream
receiveStream += webResponse.ReadLine()
End While
webResponse.Close()
Response.Write(receiveStream)=====================
Here is the web service itself:
=====================
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Description
Imports System.Web.Services.Discovery
Imports System.Web.Services.Protocols' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://betasite.com")> _
<System.Web.Script.Services.ScriptService()> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class WebService_BulkData
Inherits System.Web.Services.WebService<WebMethod(EnableSession:=True)> _
Public Function XMLServiceData() As XMLDataBlock
' Prepopulate with values to send something back by default and keep it simple
Return New XMLDataBlock With {.DBstoryid = 1, .DBstoryimagesmall = "/somefolder/default_thumb.jpg", .DBstoryimagelarge = "2big.gif", .DBstoryurl = "http://www.site2.com/", .DBstoryemail = "none yet", .DBstoryphone = "111-456-7890", .DBstorywriter = "The pollman 2", .DBstoryinstitution = "ABC 2", .DBstorytitle = "2 - Session Detected", .DBstorycontent = "2 - Serving Custom Data.", .DBstoryfullcontent = "2- The entire text of the content."}
End FunctionEnd Class
Public Class XMLDataBlock
Private _DBstoryid As Integer
Private _DBstoryimagesmall As String
Private _DBstoryimagelarge As String
Private _DBstoryurl As String
Private _DBstoryemail As String
Private _DBstoryphone As String
Private _DBstorywriter As String
Private _DBstoryinstitution As String
Private _DBstorytitle As String
Private _DBstorycontent As String
Private _DBstoryfullcontent As StringPublic Property DBstoryid() As Integer
Get
Return _DBstoryid
End Get
Set(ByVal value As Integer)
_DBstoryid = value
End Set
End Property
Public Property DBstoryimagesmall() As String
Get
Return _DBstoryimagesmall
End Get
Set(ByVal value As String)
_DBstoryimagesmall = value
End Set
End Property
Public Property DBstoryimagelarge() As String
Get
Return _DBstoryimagelarge
End Get
Set(ByVal value As String)
_DBstoryimagelarge = value
End Set
End Property
Public Property DBstoryurl() As String
Get
Return _DBstoryurl
End Get
Set(ByVal value As String)
_DBstoryurl = value
End Set
End Property
Public Property DBstoryemail() As String
Get
Return _DBstoryemail
End Get
Set(ByVal value As String)
_DBstoryemail = value
End Set
End Property
Public Property DBstoryphone() As String
Get
Return _DBstoryphone
End Get
Set(ByVal value As String)
_DBstoryphone = value
End Set
End Property
Public Property DBstorywriter() As String
Get
Return _DBstorywriter
End Get
Set(ByVal value As String)
_DBstorywriter = value
End Set
End Property
Public Property DBstoryinstitution() As String
Get
Return _DBstoryinstitution
End Get
Set(ByVal value As String)
_DBstoryinstitution = value
End Set
End Property
Public Property DBstorytitle() As String
Get
Return _DBstorytitle
End Get
Set(ByVal value As String)
_DBstorytitle = value
End Set
End Property
Public Property DBstorycontent() As String
Get
Return _DBstorycontent
End Get
Set(ByVal value As String)
_DBstorycontent = value
End Set
End Property
Public Property DBstoryfullcontent() As String
Get
Return _DBstoryfullcontent
End Get
Set(ByVal value As String)
_DBstoryfullcontent = value
End Set
End Property
End Class=============
Web Site Solution:
=============
I had VS.Net 3.5 generate the .discomap, .disco, .wsdl, .svcinfo, .svcmap files for me by using it to locate the services available to the project. Here is a break-down of what was auto-added:
/App_Code
---> WebService_BulkData.vb (the web service code you saw above)
/App_Data
/App_WebReferences
---> /localhost
--------> WebService_BulkData.discomap
--------> WebService_BulkData.disco
--------> WebService_BulkData.wsdl
---> /ServiceReference
--------> Reference.svcmap
--------> configuration.svcinfo
--------> WebService_BulkData.disco
--------> WebService_BulkData.wsdl
Default.aspx
Web.Config
WebService_BulkData.asmx=====================================================
Here's the question I had again (so you don't have to scroll all the way up):
=====================================================
1. How do I call a web service (the function to call is "WebService_BulkData") so that my aspx page will send it a SOAP request and print out the web service response data to the page? The aspx page AND the web service are part of the SAME web site project. The web site project is being developed on a beta server (not locally stored on a computer and then uploaded).Man, that sure sounds simple, doesn't it?
![]() |
0 |
![]() |
Is there a reason that you don't simply put the contents of the web method in an assembly and reference it from the web page and the web service?
![]() |
0 |
![]() |