Silverlight 4使用WCF服务返回通用列表项时出错c#

时间:2010-11-05 15:47:27

标签: silverlight wcf

尝试访问在Web应用中以标准方式托管的WCF启用Silverlight的服务时,我收到以下错误。我正在尝试将类型<ER_Theme>的列表返回到Silverlight应用程序。

这是Silveright应用程序中生成的Services.References.ClientConfig:

<configuration>
    <system.serviceModel>
        <bindings>
            <customBinding>
                <binding name="CustomBinding_ER">
                    <binaryMessageEncoding />
                    <httpTransport maxReceivedMessageSize="1000000000" maxBufferSize="1000000000" />
                </binding>
            </customBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:52377/ER.svc" binding="customBinding"
                bindingConfiguration="CustomBinding_ER" contract="ERService.ER"
                name="CustomBinding_ER" />
        </client>
    </system.serviceModel>
</configuration>

实际的服务代码如下:

 [OperationContract]
        public List<ER_Theme> GetThemes()
        {
            // Add your operation implementation here
            using (Client_BespokeEntities myDB = new Client_BespokeEntities())
            {
                List<ER_Theme> myThemes;
                myThemes = (from p in myDB.ER_Themes
                            select p).ToList();
                return myThemes;
            }
        }

这是Web App中的WebConfig设置:

<system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="SilverlightTool.Web.ER.customBinding0">
          <binaryMessageEncoding />
          <httpTransport />
        </binding>
      </customBinding>
    </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="SilverlightTool.Web.SilverlightServiceAspNetAjaxBehavior">
          <enableWebScript />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <services>
      <service name="SilverlightTool.Web.ER">
        <endpoint address="" binding="customBinding" bindingConfiguration="TMPSilverlightTool.Web.ER.customBinding0" contract="SilverlightTool.Web.ER" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>

我得到的错误如下:

{System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound.
   at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
   at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState)
   at System.Net.Browser.AsyncHelper.<>c__DisplayClass2.<BeginOnUI>b__0(Object sendState)
   --- End of inner exception stack trace ---
   at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
   at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)}

任何人都可以帮我解决这个问题吗?

2 个答案:

答案 0 :(得分:0)

它应该可以工作,可能你在代码中有另一个错误?尝试调试您的服务方法,Silverlight在服务器的任何异常中显示未找到错误。

答案 1 :(得分:0)

我的同事刚刚协助了这一点,并发现如果您在实体框架模型中禁用延迟加载,那么这将解决问题。谢谢你的建议。