Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Silverlight 4使用WCF服务返回通用列表项c时出错_Silverlight_Wcf - Fatal编程技术网

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

Silverlight 4使用WCF服务返回通用列表项c时出错,silverlight,wcf,Silverlight,Wcf,在尝试访问web应用程序中以标准方式托管的WCF Silverlight启用服务时,我遇到以下错误。我正在尝试将类型列表返回到Silverlight应用程序 这是在Silverlight应用程序中生成的Services.References.ClientConfig: <configuration> <system.serviceModel> <bindings> <customBinding>

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

这是在Silverlight应用程序中生成的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;
            }
        }
{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)}
这是Web应用程序中的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>
我得到的错误如下:

 [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;
            }
        }
{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)}

有人能帮我解决这个问题吗?

应该可以,可能是您的代码中有另一个错误?尝试调试您的服务方法时,Silverlight会在服务器的任何异常中显示not found error。

我的同事刚刚在这方面提供了帮助,并发现如果您在实体框架模型中禁用延迟加载,那么这将解决问题。谢谢大家的建议。

服务方法中的集合成功返回了一个计数为6的列表,因此我知道这方面是有效的。要获得更多信息,请尝试在InitializeComponent调用后向主窗口添加以下Xaml代码:WebRequest.RegisterPrefixhttp://,WebRequestCreator.ClientHttp;谢谢,我已经试过了,但是我得到的错误信息是相同的?你如何禁用延迟加载?我只是记得,我以前遇到过这样的问题…它只是项目中EF数据库模型的一个属性,请在这里禁用它。