Web Service / Passing Entities

Posts   
 
    
smurrell
User
Posts: 59
Joined: 22-Feb-2007
# Posted on: 23-Feb-2007 13:28:55   

Hello

I recently downloaded an eval of LLBLGen. I have gone through all the documentation supplied with LLBLGen.

I followed the instructions in the LLBLGen manual for XML Web Service support. I have created the WebServiceHelper.cs file along with the SchemaImporter. The SchemaImporter is registered with the GAC and it does this again each time I compile the solution. I have defined 1 web method and I am trying to get my client to consume the web service. I have also added my SchemaImporter to the machine.config file. The config file is correct as my web service was failing to generate until I got the machine.config right. However......

I keep on getting an error "Cannot convert type "System.Xml.XmlElement" to "ISystems.ImageWarehouse.DataLayer.EntityClasses.StorageTypeEntity".

It seems like the Reference.cs is not being generated properly. What am I doing wrong and what do you need from me to possibly help me with this.

Regards, Simon

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 23-Feb-2007 15:40:18   

Let's start by posting the Server-Side method and the Client-side caller code.

smurrell
User
Posts: 59
Joined: 22-Feb-2007
# Posted on: 23-Feb-2007 16:09:56   

Walaa wrote:

Let's start by posting the Server-Side method and the Client-side caller code.

Server Method:

       [WebMethod]
        public StorageTypeEntity HelloWorld()
        {

            StorageTypeEntity storageType = new StorageTypeEntity(1);

            return storageType;

        }

Client Method:

localhost.IWWebService webservice = new localhost.IWWebService();
            
StorageTypeEntity st = (StorageTypeEntity) webservice.HelloWorld();
ss
User
Posts: 3
Joined: 23-Feb-2007
# Posted on: 23-Feb-2007 16:43:43   

Yes, please help with this problem. I have exactly the same issue. cry

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 23-Feb-2007 17:29:37   

Could you give a stacktrace as well? What's the runtime library build nr of the ormsupportclasses? (rightclick ormsupportclasses dll in explorer -> properties -> version tab)

This is .NET 2.0 I pressume, not with WCF?

In the generated stub classes for the service (in the client that is), what are the types used there, are these indeed the entity type or a dataset ?

Frans Bouma | Lead developer LLBLGen Pro
smurrell
User
Posts: 59
Joined: 22-Feb-2007
# Posted on: 23-Feb-2007 17:40:35   

Otis wrote:

Could you give a stacktrace as well? What's the runtime library build nr of the ormsupportclasses? (rightclick ormsupportclasses dll in explorer -> properties -> version tab)

This is .NET 2.0 I pressume, not with WCF?

In the generated stub classes for the service (in the client that is), what are the types used there, are these indeed the entity type or a dataset ?

SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll File Version - 2.0.07.0111 Assembly Version - 2.0.0.0

I am using .NET 2.0. I am not using WCF.

The Reference.cs (stub class) on the client is generating XmlElement instead of StorageTypeEntity.

I have referenced my data layer dll to both the web service and the client application.

ss
User
Posts: 3
Joined: 23-Feb-2007
# Posted on: 23-Feb-2007 17:47:21   

I don't get running code yet -- it won't compile because the type can't be implicitly (or even explicitly) converted. My code is the same as the prior posts.

SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll, version 2.0.7.122

.NET 2.0

I'm not seeing any dataset types, just System.Xml.XmlElement. This is what shows in Reference.cs on the client, although Webservice clearly has an Entity return type.

I could go WCF too, but I haven't tried this at all. Would this be preferred? What's your general opinion of WCF?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 23-Feb-2007 18:05:40   

Ok, so this is a compile time error not a runtime error. Ok, I'll see what I can find. Looks like a schema error somewhere...

Frans Bouma | Lead developer LLBLGen Pro
smurrell
User
Posts: 59
Joined: 22-Feb-2007
# Posted on: 23-Feb-2007 19:19:40   

Otis wrote:

Ok, so this is a compile time error not a runtime error. Ok, I'll see what I can find. Looks like a schema error somewhere...

Hello Otis

Have you managed to find anything in the templates?

Regards, Simon

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 23-Feb-2007 19:21:54   

smurrell wrote:

Otis wrote:

Ok, so this is a compile time error not a runtime error. Ok, I'll see what I can find. Looks like a schema error somewhere...

Hello Otis

Have you managed to find anything in the templates?

Regards, Simon

Not yet, I was busy hunting down a weird oracle glitch, which is hunted down, at least it's identified.

I'll report back in this thread if / when/what I find. It could be tomorrow (saturday).

Frans Bouma | Lead developer LLBLGen Pro
smurrell
User
Posts: 59
Joined: 22-Feb-2007
# Posted on: 23-Feb-2007 20:06:27   

Otis wrote:

smurrell wrote:

Otis wrote:

Ok, so this is a compile time error not a runtime error. Ok, I'll see what I can find. Looks like a schema error somewhere...

Hello Otis

Have you managed to find anything in the templates?

Regards, Simon

Not yet, I was busy hunting down a weird oracle glitch, which is hunted down, at least it's identified.

I'll report back in this thread if / when/what I find. It could be tomorrow (saturday).

Hello Otis

Really weird.... But is it working now. I had VS open while I made the change to the machine.config file. I got bored so I closed it down. Came back to give it another shot. Added the new web reference, gave it a different name to localhost and it worked. I had also added System.Diagnostics.Debug.WriteLine to dump info to Debug View. I deleted the web reference, called it localhost again and it worked again.

Strange, maybe the closing and opening of VS refreshed something. Anyway, it is working now.

Thanks, Simon

smurrell
User
Posts: 59
Joined: 22-Feb-2007
# Posted on: 23-Feb-2007 20:08:00   

ss wrote:

I don't get running code yet -- it won't compile because the type can't be implicitly (or even explicitly) converted. My code is the same as the prior posts.

SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll, version 2.0.7.122

.NET 2.0

I'm not seeing any dataset types, just System.Xml.XmlElement. This is what shows in Reference.cs on the client, although Webservice clearly has an Entity return type.

I could go WCF too, but I haven't tried this at all. Would this be preferred? What's your general opinion of WCF?

SS, make sure your namespace in your web service matches the namespace in the EntityClassesSchemaImporter class in the "if" statement. e.g.

public override string ImportSchemaType(string name, string ns, XmlSchemaObject context, XmlSchemas schemas, XmlSchemaImporter importer, 
            CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeGenerationOptions options, CodeDomProvider codeProvider)
        {

            if (ns.Equals("http://x.y.z/xml/serialization"))
            {
                switch (name)

It could be causing your problems.

Regards, Simon

ss
User
Posts: 3
Joined: 23-Feb-2007
# Posted on: 23-Feb-2007 20:34:22   

Excellent. That combination did the trick. My namespace wasn't matching, and deleting and re-creating the web reference fixed it (I also restarted VS just in case). I've got a working web service now. Thanks! simple_smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 23-Feb-2007 20:59:02   

I can't reproduce it. My service compiles fine, and works OK. I used adapter, no inheritance on the entity and used northwind. I created everything from scratch using the steps documented.

Though I think you should check something: the Namespace on the service class. Although when I don't specify a proper namespace (e.g. use the default tempuri.org) it still works.

Be also sure the schemaimporter is indeed properly specified in the machine.config. I know this whole process sucks bigtime, but it's what MS gave us to work with disappointed

Below is my code.

service:


using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;
using NWTest.EntityClasses;
using NWTest.DatabaseSpecific;

namespace NWTestService
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://NWTest/")]
    [ToolboxItem(false)]
    public class NWTestSvc : System.Web.Services.WebService
    {
        [WebMethod]
        public CustomersEntity GetCustomer(string customerID)
        {
            CustomersEntity c = new CustomersEntity(customerID);
            using(DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.FetchEntity(c);
            }

            return c;
        }
    }
}

client:


using System;
using System.Collections.Generic;
using System.Text;
using NWTest.EntityClasses;

namespace Client
{
    class Program
    {
        static void Main(string[] args)
        {
            NWTestSvc.NWTestSvc svc = new Client.NWTestSvc.NWTestSvc();
            CustomersEntity c = svc.GetCustomer("CHOPS");
            Console.WriteLine("CustomerID:{0}. CompanyName:{1}", c.CustomerId, c.CompanyName);
        }
    }
}

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 23-Feb-2007 21:02:21   

AHA! smile . Indeed that was something Ryan, the guy who wrote the initial schema importer template, indeed mentioned, I now remember. VS.NET locked something... really weird.

Glad you all got it working.

Frans Bouma | Lead developer LLBLGen Pro