Linq error

  • Thread starter Thread starter Supremelink
  • Start date Start date
S

Supremelink

Hi all,

I have a problem with linq in a webservice.

While executing a simple query like:

var result = from customer in dbConn.Customers
select customer;

I get this error message: "Cannot use wildcards at the top level of a
schema".

I have no idea why. This is the only thing my web method contains for
the moment.

Does anyone knows about this?

Thanks in advance
Marre
 
Supremelink said:
I have a problem with linq in a webservice.

While executing a simple query like:

var result = from customer in dbConn.Customers
select customer;

I get this error message: "Cannot use wildcards at the top level of a
schema".

I have no idea why. This is the only thing my web method contains for
the moment.

Does anyone knows about this?

What LINQ provider are you using?
 
Hello Supremelink,

You need to trace SQL query of your provider to understand what's goin' on,
because the results may be different for each type of providers

see there sample how to install and use LINQ to SQL debug visualizer http://www.talentgrouplabs.com/blog/archive/2007/11/25/how-to-trace-linq-generated-sql.aspx

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


S> Hi all,
S>
S> I have a problem with linq in a webservice.
S>
S> While executing a simple query like:
S>
S> var result = from customer in dbConn.Customers
S> select customer;
S> I get this error message: "Cannot use wildcards at the top level of a
S> schema".
S>
S> I have no idea why. This is the only thing my web method contains for
S> the moment.
S>
S> Does anyone knows about this?
S>
S> Thanks in advance
S> Marre
 
What LINQ provider are you using?

Hi Jon,

I´m using LINQ to XML.

The source I´m working with are looking like this for the moment:

[WebMethod]
public XElement GetPersonUpdates()
{
WebDataContext db = new
WebDataContext(ConfigurationManager.ConnectionStrings["DB_Conn"].ConnectionString);

XElement xeCustomers = new XElement("Customers",
from customer in db.Customers
select new XElement("Customer", new object[]
{
new XAttribute("id", customer.UserID),
new XElement("firstName", customer.FirstName),
new XElement("lastName", customer.LastName),
new XElement("companyName", customer.CompanyName),
new XElement("email", customer.Email),
new XElement("phone", customer.Phone),
}
));

return xeCustomers;
}


But still.....the same error message.

/Marre
 
The problem here is that it apparently can't build any meaningful WSDL
to describe XElement. Perhaps just return string via .ToString()? Or
use typed domain entities (where it could easily generate a schema on
the fly).

Also - you don't need the new "object[]" stuff - just:

XElement("Customer",
new XAttribute("id", customer.UserID),
new XElement("firstName", customer.FirstName),
etc

Marc
 
Actually, I find the following works too; not sure if is agreeable...

[WebMethod]
public XWrapper Foo() {
return new XWraper {
Value = new XElement("Customer",
new XAttribute("id", 5),
new XElement("name", "fred")
)
};
}

[Serializable]
public class XWrapper {
[XmlElement]
public XmlElement Value {get;set;}
}
 
I´m using LINQ to XML.

I don't think you are for "var result = from customer in
dbConn.Customers select customer; "

The first step I'd suggest is trying to reproduce the error in a
console application - work out whether the problem is with SOAP, or
creating the XElement, or executing the query to start with. You've
got a whole bunch of things going on in a short space - you need to
separate them out.

Jon
 
Actually, I find the following works too; not sure if is agreeable...

[WebMethod]
public XWrapper Foo() {
return new XWraper {
Value = new XElement("Customer",
new XAttribute("id", 5),
new XElement("name", "fred")
)
};

}

[Serializable]
public class XWrapper {
[XmlElement]
public XmlElement Value {get;set;}

}

Hi Marc,

This really seems to work! Thanks!!!

A stupid question maybe, but how come it´s working with this new class
XWrapper?

/Marre
 
Because it can generate a schema for it... it *has* a definite
top-level element (XWrapper) - where-as in your example it can't know
(until runtime) that the top-level element is Customer.

Of course, this still just exposes your data as raw xml, which doesn't
make it easy to consume; I would recommend a Customer class with
defined properties; you could arguably use your data-context entites,
but that would make it hard to change the interfaces separately (I
remember Dominick Baier trying to convince me that separate internal
and public entities was a perfectly reasonable and good thing...) -
plus it avoids having to edit the auto-generated entity classes...

(following is "notepad" code; not tested in the least)

[Serializable]
public class Customer {
[XmlAttribute("id")]
public int Id {get; set;}
[XmlElement("firstName")]
public string FirstName {get;set;}
// etc
}

[WebMethod]
public Customer[] GetCustomers() {
var query = from customer in db.Customers
select new Customer {
Id = customer.UserID,
FirstName = customer.FirstName // etc
};
return query.ToArray();
}
 
oh, btw, to get the outer "Customers" (rather than ArrayOfCustomer),
you can use:

[WebMethod]
[return: XmlRoot("Customers")]
public Customer[] Foo() {
// ...
}

Marc
 
oh, btw, to get the outer "Customers" (rather than ArrayOfCustomer),
you can use:

[WebMethod]
[return: XmlRoot("Customers")]
public Customer[] Foo() {
// ...

}

Marc

Marc,

Many thanks

You will get a star next to you're name in "my book" ;)

Best regards
Marre
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top