0

I have 3 classes called Result, Col and Tuple. They essentially represent a database query for serialization. These are exposed using a Web Service (System.Web.Services.WebService). This Web service is then consumed by another web service (System.ServiceModel.ServiceHost) which manipulates the data. The problem is the second web service is consumed by another client it cannot read any of the data.

Here are the 3 classes (With a bit of fluff removed):

Result Class

public class Result
{
    public List<Col> Columns { get; set; }
    public List<Tuple> Tuples { get; set; }
}

Column Class

public class Col
{
    public string ColumnName;
    public int? ColumnSequence;
    public string DataType;
    public int? DataLength;
    public int? DataPrecision;
    public int? DataScale;
    public bool? AllowDbNull;
    public bool? IsReadOnly;
    public bool? IsLong;
    public bool? IsKey;
    public string KeyType;
    public bool? IsUnique;
    public string Description;
}

Tuple

public class Tuple
{
    public List<object> Values = new List<object>();
}

Exposing Function

[WebMethod]
public Result Query(string sql, object[] arguments)
{
    using (var Conn = Utilities.GetConnection(true))
        return Conn.Query(sql, arguments);
}

For some better explanation, I essentially query a database in the second Web Service; however, I recycle the data structure used to store the result. So when the client queries the second web service, it just gives it just fills out the data structure and sends it to the calling client.

Here is the second web Service:

[OperationContract]
public Result QuerySource(String companyCode, String commandText, params object [] arguments)
{
    using (var Connection = ClientSettings.Instance.GetOpenConnectionByCode(companyCode))
        return Connection.Query(commandText, arguments);
}

I used the following code :

public static string ToXml(this Result result)
{
   using (var stringwriter = new StringWriter(CultureInfo.CurrentCulture))
   { 
        new XmlSerializer(result.GetType()).Serialize(stringwriter, result);
        return stringwriter.ToString();
   }
}

and I get :

<?xml version="1.0" encoding="utf-16"?>
<Result xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Columns xmlns="http://pmh.plexxis.com">
    <Col>
      <ColumnName>DUMMY</ColumnName>
      <ColumnSequence xsi:nil="true" />
      <DataType>System.String</DataType>
      <DataLength xsi:nil="true" />
      <DataPrecision xsi:nil="true" />
      <DataScale xsi:nil="true" />
      <AllowDbNull xsi:nil="true" />
      <IsReadOnly>false</IsReadOnly>
      <IsLong>false</IsLong>
      <IsKey>false</IsKey>
      <IsUnique>false</IsUnique>
    </Col>
  </Columns>
  <Tuples xmlns="http://pmh.plexxis.com">
    <Tuple>
      <Values>
        <anyType xsi:type="xsd:string">X</anyType>
      </Values>
    </Tuple>
  </Tuples>
</Result>

I suspect this has smething to do with the name spaces. Any help would be appreciated.

Aelphaeis
  • 2,593
  • 3
  • 24
  • 42
  • What do you expect to see? – CodeCaster May 28 '14 at 21:18
  • Anything, when I run the query on the client I get a flat out null pointer exception. – Aelphaeis May 28 '14 at 21:23
  • Then see [What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it). You should apply that to the client. – CodeCaster May 28 '14 at 21:24
  • The issue here is that its not null before it gets to the client. It's only null after the client tries to serialize it. The serialization is not intended to return null. It should return a structure like the Xml Example shows. – Aelphaeis May 28 '14 at 21:31
  • You need to analyze the stack trace and then place breakpoints to analyze what is null and when. See linked question on how to do so. That can't be determined using the code you posted. – CodeCaster May 28 '14 at 21:33
  • I don't think you understand. There is a web service and the web service returns a value; however, when the program gets the value it returns null. I've gone as far into the stack trace as visual studio will let me but I can't see how visual studio serializer works. – Aelphaeis May 28 '14 at 21:36
  • 1
    Yes, so you're asking, "How can this code return something that makes other code throw an exception". I would suspect either the `Conn.Query()` implementation or the parameters you feed it. You say your problem is though you see XML but your client throws a `NullReferenceException`. I would like to see the stack trace of that in your question to make sure you're looking in the right spot. – CodeCaster May 28 '14 at 21:43

0 Answers0