Oliver
Oliver

Reputation: 817

WCF service not working because of return data type?

I have created a WCF service with 2 methods :

[ServiceContract(Namespace = "")]
[SilverlightFaultBehavior]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MyDataService
{
    [OperationContract]
    public IQueryable<object> Service1()
    {
        PivotData pivot = new PivotData();
        IQueryable<object> list = pivot.GeneratePivotData();
        return list;
    }
[OperationContract]
public string Service2()
{
    return "hello";
}

}

The Service2 works perfectly fine. However , service1 returns the dreaded "the remote server has returned an error : not found"

I believe it has to do with the return type IQueryable<object> , but I don't know what I should change to make it work. I tried List<string> , ObservableCollection<object> and a few others but to no avail.

What should I do the get my data back to the client ?

Thanks

Upvotes: 0

Views: 358

Answers (1)

Davut G&#252;rb&#252;z
Davut G&#252;rb&#252;z

Reputation: 5716

depending on the question and conversation with Aron.

I supposed it is a WCF-Ria Services If so please retag the question, otherwise you may ignore this answer.

Try the below code.

Beside if you use ria services. you should use , [Association("FK_assos_name", "field", "field")] [Include] for complex properties and your base class should have at least one [Key] attributed field. Such as ID.

[OperationContract]
public BaseClass[] ServiceMethod1()
{
    PivotData pivot = new PivotData();
    IQueryable<object> list = pivot.GeneratePivotData();
    return list.ToArray();
}

If you still get errors trace it;In your web.config add the lines below. Then open WcfDetailTrace.svclog with svclog viewer. Red parts will show you what goes wrong.

<system.diagnostics> 
<trace autoflush="true"> 
    <listeners> 
    </listeners> 
</trace> 
<sources> 
    <source name="System.ServiceModel" 
            switchValue="Information, ActivityTracing" 
            propagateActivity="true"> 
        <listeners> 
            <add name="sdt" 
                 type="System.Diagnostics.XmlWriterTraceListener" 
                 initializeData= "WcfDetailTrace.svclog" /> 
        </listeners> 
    </source> 
</sources> 

Upvotes: 1

Related Questions