开发者

Silverlight 4 Error using WCF services to return Generic List items c#

开发者 https://www.devze.com 2023-01-24 04:28 出处:网络
I am getting the below error when trying to access a WCF Silverlight enabled service hosted in a standard way in a web app. I am trying to return a List of type <ER_Theme> to the Silverlight app

I am getting the below error when trying to access a WCF Silverlight enabled service hosted in a standard way in a web app. I am trying to return a List of type <ER_Theme> to the Silverlight app.

This is the Services.References.ClientConfig generated in the Silveright app:

<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>

The actual Service code is as follows:

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

This is the WebConfig settings in the Web App:

<system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="SilverlightTool.Web.ER.customBinding0">
          <binaryMessageEncoding />
          <httpTransport />
        </binding>
      </customBind开发者_运维百科ing>
    </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>

The error I'm getting is as follows:

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

Can anyone help me out with this?


It should work, may be you have another error in code? try to debug your service method, Silverlight shows not found error in any exception from the server.


My colleague has just assisted in this and has found that if you disable Lazy Loading in your entity framework model then this will solve the issue. Thanks for the suggestions guys.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号