0

我用 2 种方法创建了一个 WCF 服务:

[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";
}

}

Service2 工作得很好。但是,service1 返回可怕的“远程服务器返回错误:未找到”

我相信它与返回类型有关IQueryable<object>,但我不知道我应该改变什么才能让它工作。我试过了List<string>ObservableCollection<object>还有一些其他的,但无济于事。

我应该怎么做才能将我的数据返回给客户端?

谢谢

4

1 回答 1

1

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> 

于 2013-05-08T10:00:40.813 回答