Problem between Web services and ASP application

mike55

Contributor
Joined
Mar 26, 2004
Messages
727
Location
Ireland
Hi all

am having the following problem between my asp frontend and the web server back end:
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type System.String[] may not be used in this context. at System.Xml.Serialization.XmlSerializationWriter.WriteTypedPrimitive(String name, String ns, Object o, Boolean xsiType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write1_Object(String n, String ns, Object o, Boolean isNullable, Boolean needType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write11_wsCustomer_viewCustomerDataResponse(Object[] p) --- End of inner exception stack trace --- at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle) at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces) at System.Web.Services.Protocols.SoapServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream) at System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues) at System.Web.Services.Protocols.WebServiceHandler.Invoke() --- End of inner exception stack trace ---

Now my database code is correct, the problem arises when I go to send the data back to the frontend. Here is my code for the backend:
Code:
Imports System
Imports System.Data
Imports System.Data.SqlClient

 <WebMethod(Description:="View data on a customer.")> _
    Public Function wsCustomer_viewCustomerData(ByVal customerName As String)
         Try
            Dim daDataAdapter As New SqlDataAdapter
            Dim dsDataset As New DataSet
            Dim returnData(11) As String
            result = False
            'Open the connection
            conSQL = SQLConnection.connectSQL()
            conSQL.Open()

            'Execute the statement
            commSQL.Connection = conSQL
            commSQL.CommandType = CommandType.Text

            'Construct the SQL command & Execute
            commSQL.CommandText = "Select  CustomerRef, CustomerName, CustomerType, Address, County, Phone, Fax, Email, MinCallRate, MaxCallRate, Comments from Customers where CustomerName = '" + CustomerName + "' and status = 1"
            drDataReader = commSQL.ExecuteReader

            While (drDataReader.Read())
                returnData(0) = drDataReader.GetSqlInt32(0).ToString    'ref
                returnData(1) = drDataReader.GetString(1)               'name
                returnData(2) = drDataReader.GetString(2)               'type
                returnData(3) = drDataReader.GetString(3)               'address
                returnData(4) = drDataReader.GetString(4)               'county
                returnData(5) = drDataReader.GetString(5)               'phone
                returnData(6) = drDataReader.GetString(6)               'fax
                returnData(7) = drDataReader.GetString(7)               'Email
                returnData(8) = drDataReader.GetString(8)               'MinCallRate
                returnData(9) = drDataReader.GetString(9)               'MaxCallRate()
                returnData(10) = drDataReader.GetString(10)             'Comments
            End While
            drDataReader.Close()

            conSQL.Close()

            Return returnData

        Catch ex As Exception
            conSQL.Close()
            Throw ex
        End Try
    End Function

And here is my frontend code:
Code:
'Get the data
        Dim returnData(11) As String
        returnData = wsCustomer.wsCustomer_viewCustomerData(ddCustomers.SelectedValue.ToString.Replace("'", "`"))
        lblRef.Text = returnData(0)
        txtName.Text = returnData(1)
        ddCustomerType.SelectedItem.Text = returnData(2)
        txtAddress.Text = returnData(3)
        txtCounty.Text = returnData(4)
        txtPhone.Text = returnData(5)
        txtFax.Text = returnData(6)
        txtEmail.Text = returnData(7)
        txtMinCallRate.Text = returnData(8)
        txtMaxCallRate.Text = returnData(9)
        txtComments.Text = returnData(10)

Would appreciate any suggestions.

Mike55
 
Try changing the webmethod declaration to
Visual Basic:
<WebMethod(Description:="View data on a customer.")> _
    Public Function wsCustomer_viewCustomerData(ByVal customerName As String) as string()

Also you may find putting Option Strict On at the top of the source file will prevent problems like this slipping through.
 
PlausiblyDamp said:
Try changing the webmethod declaration to
Visual Basic:
<WebMethod(Description:="View data on a customer.")> _
    Public Function wsCustomer_viewCustomerData(ByVal customerName As String) as string()

Also you may find putting Option Strict On at the top of the source file will prevent problems like this slipping through.


Hi

Am still getting the following error, but with a different page this time:
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type System.String[] may not be used in this context. at System.Xml.Serialization.XmlSerializationWriter.WriteTypedPrimitive(String name, String ns, Object o, Boolean xsiType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write1_Object(String n, String ns, Object o, Boolean isNullable, Boolean needType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write47_wsTimeDetail_getTimeDataResponse(Object[] p) --- End of inner exception stack trace --- at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle) at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces) at System.Web.Services.Protocols.SoapServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream) at System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues) at System.Web.Services.Protocols.WebServiceHandler.Invoke() --- End of inner exception stack trace ---

Now on going through my code, i nearly positive that the problem is to do with the references...

In relation to adding Option Strict On to the source file, where do i add it and what do you mean by the source file (dumb question, i know!)

Mike55
 
Are you getting the other error calling the same function or a different one?

You can just type Option Strict at the very top of each of the .vb files (classes, code-behind etc.)
 
PlausiblyDamp said:
Are you getting the other error calling the same function or a different one?

You can just type Option Strict at the very top of each of the .vb files (classes, code-behind etc.)

I don't think that Option Strict is an option creates a hell of a lot more errors than it solves.

The function works perfectly if I am passing dataset or single string variables between the webservice and the frontend. However the minute I switch to a string() all hell breaks loose.

Mike55
 
Are you declaring return types on all your functions? If not then you will get errors at run-time.
Although Option Strict may cause lots of errors it is only highlighting places where you have potential problems - if you can fix them in the compiler you will not have to keep suffering crashes at run-time.
 
PlausiblyDamp said:
Are you declaring return types on all your functions? If not then you will get errors at run-time.
Although Option Strict may cause lots of errors it is only highlighting places where you have potential problems - if you can fix them in the compiler you will not have to keep suffering crashes at run-time.


IT WORKS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Don't know why, but the damn think works...Thanks for the help.

Mike55
 
If you do not specify a return type it assumes object - this will not always result in the correct behaviour at run-time. Option Strict is a good way to catch these things.
 
Back
Top