简体   繁体   English

Silverlight应用程序中的WCF服务

[英]WCF Service in Silverlight Application

I have a Silverlight 5 application that is obtain data from a Silverlight-enabled WCF service in another project (my solution has a Silverlight project and a web project). 我有一个Silverlight 5应用程序,该应用程序是从另一个项目中启用了Silverlight的WCF服务中获取数据的(我的解决方案有一个Silverlight项目和一个Web项目)。 There are a number of similar posts, but they're referring to web services hosted on a web server (proper web services). 有许多类似的文章,但是它们是指托管在Web服务器上的Web服务(正确的Web服务)。

I am aware that I have to tell the application where to find the service in both dev and prod. 我知道我必须告诉应用程序在哪里可以在dev和prod中找到服务。 In dev, you'll have a port typically. 在开发人员中,通常会有一个端口。 My code to create a service client (with the correct EndpointAddress) is as such: 我创建服务客户端(具有正确的EndpointAddress)的代码如下:

BasicHttpBinding binding = new BasicHttpBinding(
        Application.Current.Host.Source.Scheme.Equals("https", StringComparison.InvariantCultureIgnoreCase)
        ? BasicHttpSecurityMode.Transport : BasicHttpSecurityMode.None);
binding.MaxReceivedMessageSize = int.MaxValue;
binding.MaxBufferSize = int.MaxValue;
Uri tempUri = new Uri("../PolicyDataService.svc", UriKind.Relative);
EndpointAddress servAddr = new EndpointAddress(tempUri);
PolicyDataServiceClient temp = new PolicyDataServiceClient("BasicHttpBinding_PolicyDataService", servAddr);
return temp;

Now, where am I going wrong? 现在,我哪里出问题了? In dev, everything works fine, but in prod the service is never being called. 在开发人员中,一切正常,但是在生产中,永远不会调用该服务。 Thanks! 谢谢!

I'm not sure what's going on, but here are a few things that you can try if you haven't already: 我不确定发生了什么,但是如果您还没有尝试,可以尝试以下操作:

  1. Browse to the svc file on Prod and make sure you can access it (http://yoursite/PolicyDataService.svc) 浏览到Prod上的svc文件,并确保您可以访问它(http://yoursite/PolicyDataService.svc)
  2. Point your code to the prod location and make sure you can connect without any issue. 将您的代码指向产品位置,并确保您可以正确连接。 Doing this will usually reveal what the problem is, provided you can connect. 只要您可以连接,执行此操作通常就会发现问题出在哪里。

Since you're using BasicHttpBinding, you shouldn't be running into security issues with the binding. 由于您使用的是BasicHttpBinding,因此您不应该在绑定方面遇到安全性问题。 I know this is pretty basic, but have to start somewhere. 我知道这是非常基本的,但是必须从某个地方开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM