Unpredictable WebService Results

littlemuroo

New Member
My last entry (May 14, "THE SAGA CONTINUES") was written at the end of a hard day when I was frustrated, angry, tired, and on the verge of insanity. Therefore, upon reading again this morning, I realized that it probably wasn't very clear or to the point. For this reason I will attempt to describe the situation a little better.<BR><BR>I've built a WebService contained in the file "DataAccessTest.asmx". It's namespace is "nsDataAccess". It contains a class, "DataAccess", which exposes a single method, "ShowData()". This method takes in two parameters, "ConnectionString" and "SQLQuery", both strings and both pretty self-explanatory. If zero-length strings are sent in, default values are used in their place.<BR><BR>The default ConnectionString value is obtained by calling a function, "GetDefaultConnectionString()". This function uses a HashTable object to grab the default string from the config.web file as shown below:<BR><BR>*************************************************<BR>Private Function GetDefaultConnectionString() as String<BR>dim htAppSettings as HashTable = Context.GetConfig("appsettings")<BR>GetDefaultConnectionString = htAppSettings("MyConnStrKey")<BR>End Function<BR>*************************************************<BR><BR>Once the ConnectionString value and SQLQuery value (whether they be default values or parameter values) are obtained, the function, "GetXMLResultSet()", is called. This function uses ADOConnection, ADOCommand, and ADOReader objects to get a resultset based upon the ConnectionString and SQLQuery values passed in. Once the resultset is obtained, an XML string is built, populated with the data obtained from the resultset, and then sent back to the calling function.<BR><BR>This XML string is what is returned by the "ShowData()" method of the "DataAccess" class.<BR><BR>Now, when I call this WebService up in my browser, it works beautifully. I can access its single method just fine to obtain the XML string. I can view its SDL. Everything is as it should be. However, when I try to access it from an ASP.NET page, I get errors.<BR><BR>I am using "Basic" authentication. The default connection string used by the WebService is: "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Parcel;Data Source=NTSQLASQL2KDEVL". In my config.web file, I have "impersonation" set to "true" and "authentication mode" set to "none". I am using a SQLServer2K remote database which sits on an NT box. My local box is a Win2K box.<BR><BR>In order to compile the WebService file into a proxy class/DLL using WebServiceUtil.exe, I've had to change my authentication to "Anonymous"/"Integrated" and then change it back to "Basic" once I've finished so I could view my files via my browser.<BR><BR>Having said all of that, here is one error that I receive when trying to pull up "dataaccess2.aspx" (which is the page that calls the ShowData() method from the WebService) in my browser:<BR><BR>---------------------------------------------<BR>You are not authorized to view this page<BR>...<BR>HTTP 401.2 - Unauthorized: Logon failed due to server configuration<BR>Internet Information Services<BR>...<BR>Background:<BR>This is usually caused by a server-side script not sending the proper WWW-Authenticate header field. Using Active Server Pages scripting this is done by using the AddHeader method of the Response object to request that the client use a certain authentication method to access the resource. <BR>---------------------------------------------<BR><BR>That's one error I get. Here's the piece of code, by the way, that calls the method of the WebService from the ASP.NET page:<BR><BR>************************************<BR>private function GetXMLString(byval sConnStr as string, byval sQueryStr as string) as string<BR>dim oDA as new DataAccess<BR>GetXMLString = oDA.ShowData(sConnStr, sQueryStr)<BR>end function<BR>************************************<BR><BR>The error mentioned above occurs at the line which says, "GetXMLString = oDA.ShowData(sConnStr, sQueryStr)". Now, in order to bypass this method call which is causing the error above, I have experimented by changing the code to look like the following"<BR><BR>************************************<BR>private function GetXMLString(byval sConnStr as string, byval sQueryStr as string) as string<BR>'dim oDA as new DataAccess<BR>'GetXMLString = oDA.ShowData(sConnStr, sQueryStr)<BR>GetXMLString = "<recs><rec customerid=""TESTCUST"" companyname=""TestCo, Inc."" contactname=""Ima Kohntak"" contacttitle=""Minister of Defense"" /></recs>"<BR>end function<BR>************************************<BR><BR>As can be seen in that code snippet, rather than trying to get the XML string from the WebService method, one is being created on the fly and sent back. When I do this, I get two results (interestingly enough). Either it works and the on-the-fly XML is displayed, or I get the following error:<BR><BR>-----------------------------------<BR>Could not load assembly 'genXX'. Please make sure that your assemblies are placed in C:TonyTestsdotNETin or are globally accessible <BR>-----------------------------------<BR><BR>Note that 'genXX' above appears as 'gen94' or 'gen76' or 'gen8b' and other such combinations.<BR><BR>But the plot thickens.....I mentioned that sometimes I receive an error and sometimes I don't. I will now expound on that further. You will notice that in the last code snippet I included above, that I commented out the "dim oDA as new DataAccess" line. If I try to run the script that way, I may or may not recieve an error. The result remains the same if I refresh the browser screen after having loaded the page. That is to say, if I receive an error, the error remains no matter how many times I refresh the screen, as one would expect. Then, I uncomment it and may or may not receive an error. Again, the result remains upon refreshing the screen. What is so odd is that if I comment the line out once again, I could very recieve an error where before I did not - or I may not receive one. It's very unpredictable.<BR><BR>I don't know if any of this has really made a whole lot of sense to the reader without him actually being here to see the results. I hope that I have explained myself well. I am thoroughly confused as to why:<BR><BR>1) The exact same code will produce varying results.<BR>2) My WebService can access the SQLServer and work beautifully on its own, but I cannot call it from an ASP.NET page to do the same work.<BR><BR>If anyone has any suggestions or insight, please let me know.<BR><BR>I think that .NET has wonderful potential and can be very powerful for web development, but I am quickly becoming disenchanted with the lack of documentation and the unpredictable results I've been experiencing. I hope these buggy issues get taken care of in the Beta 2 release and in future versions because I would very much like to use .NET 100% of the time - I am just getting a little frustrated with the Beta 1 version so far.<BR><BR>Again, any help would be greatly appreciated.<BR><BR>Thank you,<BR><BR>~~ Tony<BR><BR>P.S. Below are the two files mentioned in this entry. I apologize if wrapping makes it hard to read - it can be copied into some other text editor to be more easily read.<BR><BR>****************** dataaccesstest2.aspx ******************<BR><%@ Page Language="vb" Trace="false" %><BR><%@ Import NameSpace="System.XML" %><BR><%@ Import NameSpace="System.XML.XSL" %><BR><%@ Import NameSpace="System.IO" %><BR><%@ Import NameSpace="nsDataAccess" %><BR><BR><script language="vb" runat="server"><BR>private sub Page_Load(Sender as Object, E as EventArgs)<BR>dim sXML as string<BR>dim sTransformedOutput as string<BR>dim oXMLDoc as new XMLDocument<BR>dim oXSLT as new XSLTransform<BR>dim oDocNav as DocumentNavigator<BR>dim oStringWriter as new StringWriter<BR><BR>sXML = GetXMLString("", "")<BR>oXMLDoc.loadXML(sXML)<BR>oDocNav = new DocumentNavigator(oXMLDoc)<BR>oXSLT.load(Server.MapPath("MyTransformationDocument.xsl"))<BR>oXSLT.Transform(oDocNav, nothing, oStringWriter)<BR>sTransformedOutput = oStringWriter.ToString<BR>oStringWriter.Close<BR> <BR>lblXML.text = sTransformedOutput<BR>end sub<BR><BR>private function GetXMLString(byval sConnStr as string, byval sQueryStr as string) as string<BR>dim oDA as new DataAccess<BR>GetXMLString = oDA.ShowData(sConnStr, sQueryStr)<BR>end function<BR></script><BR><BR><html><BR><body><BR><BR><font face="arial" size="2"><BR><asp:label id="lblXML" text="" runat="server" /><BR></font><BR><BR></body><BR></html><BR>************************************************** ********<BR><BR>****************** DataAccess.asmx ******************<BR><%@ WebService Language="VB" Class="DataAccess"%><BR><BR>Imports System<BR>Imports System.Web.Services<BR>Imports System.Data<BR>Imports System.Data.ADO<BR>Imports System.Text<BR>Imports System.Collections<BR><BR>Public Class DataAccess : Inherits WebService<BR><BR>Public Function <WebMethod()> ShowData(ByVal ConnectionString As String, ByVal SQLQuery As String) As String<BR>dim sResult as String<BR>dim sbTemp as StringBuilder<BR>dim sDefaultConnStr as String = GetDefaultConnectionString()<BR>dim sDefaultQueryStr as String = "select top 50 * from table"<BR> <BR>'Trim down the parameters passed in<BR>ConnectionString = ConnectionString.Trim<BR>SQLQuery = SQLQuery.Trim<BR> <BR>if (ConnectionString.Length > 0) and (SQLQuery.Length > 0) then<BR>'Use both input parameters<BR>sResult = GetXMLResultSet(ConnectionString, SQLQuery)<BR>else<BR>if (ConnectionString.Length > 0) and (not (SQLQuery.Length > 0)) then<BR>'Use the default query string<BR>sResult = GetXMLResultSet(ConnectionString, sDefaultQueryStr)<BR>elseif (SQLQuery.Length > 0) and (not (ConnectionString.Length > 0))<BR>'Use the default connection string<BR>sResult = GetXMLResultSet(sDefaultConnStr, SQLQuery)<BR>elseif (not (ConnectionString.Length > 0)) and (not (SQLQuery.Length > 0))<BR>'Use both defaults<BR>sResult = GetXMLResultSet(sDefaultConnStr, sDefaultQueryStr)<BR>end if<BR>end if<BR> <BR>sbTemp = new StringBuilder(sResult)<BR>sResult = sbTemp.Replace("&", "&amp;").ToString()<BR> <BR>ShowData = http://aspmessageboard.com/archive/index.php/sResult<BR>End Function<BR> <BR>Private Function GetXMLResultSet(byval sConnStr as String, byval sQueryStr as String) as String<BR>dim oConn as ADOConnection<BR>dim oCmd as ADOCommand<BR>dim oDR as ADODataReader<BR>dim sXML as String<BR> <BR>oConn = new ADOConnection(sConnStr)<BR>oCmd = new ADOCommand(sQueryStr, oConn)<BR>oConn.Open<BR>oCmd.Execute(oDR)<BR> <BR>sXML = "<recs><err msg="""" />"<BR>do while oDR.Read()<BR>sXML = sXML & "<rec "<BR>dim i as Integer<BR>for i = 0 to (oDR.FieldCount - 1)<BR>'Write the attribute names in lowercase<BR>sXML = sXML & oDR.GetName(i).Trim.ToLower() & "="<BR>if not oDR.IsNull(i) then<BR>sXML = sXML & """" & oDR.GetValue(i) & """ "<BR>else<BR>sXML = sXML & """"" "<BR>end if<BR>next<BR>sXML = sXML & "/>"<BR>loop<BR>sXML = sXML & "</recs>"<BR> <BR>oDR.Close<BR>oConn.Close<BR> <BR>GetXMLResultSet = sXML<BR>End Function<BR> <BR>Private Function GetDefaultConnectionString() as String<BR>dim htAppSettings as HashTable = Context.GetConfig("appsettings")<BR>GetDefaultConnectionString = htAppSettings("MyConnStrKey")<BR>End Function<BR><BR>End Class<BR>************************************************** ***
 
Back
Top