在服务器上部署后,Silverlight WCF 服务不从数据库返回任何数据

Silverlight WCF services not returning any data from database, after deploying on server

我有一个 silverlight 应用程序,它使用 wcf 服务 从数据库(SQL 服务器)读取数据,而不使用 entity framework,单击一个按钮。我部署在我的本地系统上,它工作正常。我在服务器上部署并发布了它。我打开页面,点击按钮获取数据。但是它不显示数据,也不显示任何错误。 我很困惑可能是什么问题,在哪一边。

多数情况下可能是访问数据库造成的。以下步骤可能对您有所帮助:

  • 检查您的 WCF 服务是否可以访问。
  • 检查WCF配置中的连接字符串是否正确

如果要查看WCF服务,有两种方法:

您可以通过如下代码生成代理

假设您通过添加服务引用自动生成了代理。

当您尝试访问您的 WCF Web 方法时,您需要一个服务客户端。让我们说它的 SomeProxyClient.

在你的数据服务中 class/anywhere 你使用了一个 属性 类型的 SomeProxyClient

在 属性 的 getter 方法中使用您的 WCF 服务尝试以下代码 URL

私人 SomeProxyClient _proxy;

SomeProxyClient Proxy
    {

        get
        {

            if (_proxy == null)
            {
                var binding = new BasicHttpBinding
                {
                    MaxReceivedMessageSize = 2147483647,
                    MaxBufferSize = 2147483647

                };

                Uri uri = null;
                if (!System.ComponentModel.DesignerProperties.IsInDesignTool)
                {
                    hostName = HtmlPage.Document.DocumentUri.Host;
                    portNo = HtmlPage.Document.DocumentUri.Port;

                        uri = new Uri("http://" + hostName + ":" + portNo.ToString() + "/y/x.svc");

                }
                else
                {
                    uri = new Uri("http://localhost:2700/x.svc");
                }

                _proxy = new SomeProxyClient(binding, new EndpointAddress(uri));
                _proxy.Endpoint.Binding.CloseTimeout = new TimeSpan(01, 20, 10);
                _proxy.Endpoint.Binding.ReceiveTimeout = new TimeSpan(01, 20, 10);
                _proxy.Endpoint.Binding.SendTimeout = new TimeSpan(01, 20, 10);
                _proxy.Endpoint.Binding.OpenTimeout = new TimeSpan(01, 20, 10);

                return _proxy;
            }
            return _proxy;
        }
    }

然后通过使用此变量,您可以访问您的 WCF Web 方法。

通过这种方式,您不必一直接触服务引用,即从开发到生产部署。它会自动获取相应的服务器和端口地址。

希望对您有所帮助

听起来您的 IIS 无法处理 .svc 请求。

如果是这种情况,您也许可以在这里找到一些东西 - WCF Service Deployment in IIS Page cannot be displayed and how does the SVC file work?

实际上问题出在 web.config 文件中设置端点地址,而且随着服务部署到其他机器上,应用程序的 URL 也发生了变化。所以我做了下面给出的一些重要更改: 1. 在 web.config 文件中提供与 ServiceRefrence.ClientConfig 文件中相同的端点地址、端点名称和合同详细信息。 2. 更改 ServiceRefrence.ClientConfig 中没有特定端口详细信息的端点地址:http://Localhost/..... 而不是 http://Localhost:56279/..... 和 3. 在应用程序中编码以获取其执行所在机器的 URI 地址,以便无论何时何地该应用程序已部署用户不必担心本地主机地址及其端口详细信息:Uri servUri = new Uri("../Service.svc", UriKind.Relative); EndpointAddress servAddr = new EndpointAddress(servUri); ServiceReferenceForSelect.ServiceForSelectClient objSelect = new ServiceForSelectClient("BasicHttpBinding_IService", servAddr); 这解决了问题。感谢大家的帮助。