“启用了Silverlight的WCF服务”应该怎样发布

starrytravel 2012-03-24 05:38:58
“启用了Silverlight的WCF服务”应该怎样发布?

情况:
解决方案中有一个“asp.net站点”,一个“Silverlight”项目,用“启用了Silverlight的WCF服务”提供数据服务。

配置:
1、IIS6.0/7.5,MIME类型配置正确,“XAP文件”正常显示。
2、跨域访问文件,如下:
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="*">
<domain uri="*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>

3、“crossdomain.xml”文件
根目录下又放置了“crossdomain.xml”文件:

<?xml version="1.0" ?>
<cross-domain-policy>
<allow-access-from domain="*" />
<site-control permitted-cross-domain-policies="all" />
<allow-http-request-headers-from domain="*" headers="*" />
</cross-domain-policy>

4、节点配置(VS2010)自动生成
Silverlight客户端:
<configuration>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="CustomBinding_ChartsService">
<binaryMessageEncoding />
<httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
</binding>
<binding name="CustomBinding_ChartsService1">
<binaryMessageEncoding />
<httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://localhost:2686/Mycems.UI/ChartsService.svc"
binding="customBinding" bindingConfiguration="CustomBinding_ChartsService"
contract="ChartsService.ChartsService" name="CustomBinding_ChartsService" />
<endpoint address="http://localhost:4707/Mycems.UI/ChartsService.svc"
binding="customBinding" bindingConfiguration="CustomBinding_ChartsService1"
contract="MyChartsService.ChartsService" name="CustomBinding_ChartsService1" />
</client>
</system.serviceModel>
</configuration>

服务器端(Web.config): <behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="ChartsService">
<endpoint address="" binding="customBinding" bindingConfiguration="ChartsService.customBinding0"
contract="ChartsService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="WeatherWebServiceSoap" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
<customBinding>
<binding name="WeatherWebServiceSoap12">
<textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
messageVersion="Soap12" writeEncoding="utf-8">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</textMessageEncoding>
<httpTransport manualAddressing="false" maxBufferPoolSize="524288"
maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
bypassProxyOnLocal="false" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard"
keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
useDefaultWebProxy="true" />
</binding>
<binding name="ChartsService.customBinding0">
<binaryMessageEncoding />
<httpTransport />
</binding>
</customBinding>
</bindings>


问题:“Silverlight”访问不到部署在“IIS6”上的“WCF Servcie服务”,获取不了数据,怎么回事?

是不是需要对节点,进行什么配置???因为配置内容是在“VS2010”中自动生成的,所以在VS2010中一切正常

错误信息如下:
根目录下又放置了“crossdomain.xml”文件:

<?xml version="1.0" ?>
<cross-domain-policy>
<allow-access-from domain="*" />
<site-control permitted-cross-domain-policies="all" />
<allow-http-request-headers-from domain="*" headers="*" />
</cross-domain-policy>

但是还是报错,信息如下:
网页错误详细信息

用户代理: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3; Zune 4.7; .NET CLR 1.1.4322)
时间戳: Sat, 24 Mar 2012 09:13:32 UTC


消息: Unhandled Error in Silverlight Application 操作过程中出现异常,结果无效。有关异常的详细信息,请查看 InnerException。 位于 System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
位于 MyCharts.MyChartsService.GetWaterMonitoringDatasCompletedEventArgs.get_Result()
位于 MyCharts.WaterMonitoring.client_GetWaterMonitoringDatasCompleted(Object sender, GetWaterMonitoringDatasCompletedEventArgs e)
位于 MyCharts.MyChartsService.ChartsServiceClient.OnGetWaterMonitoringDatasCompleted(Object state)
行: 1
字符: 1
代码: 0
URI: http://10.10.233.120/Tj/Web/WaterMonitoring.aspx









...全文
343 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
tianxia_rwx 2013-03-28
  • 打赏
  • 举报
回复
不错,应该可以解决我的问题!
starrytravel 2012-03-29
  • 打赏
  • 举报
回复
为什么有两个地址???
starrytravel 2012-03-28
  • 打赏
  • 举报
回复
为什么有两个地址???
starrycheng 2012-03-25
  • 打赏
  • 举报
回复
为什么会有两个地址???
starrycheng 2012-03-24
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 taomanman 的回复:]

之前不是跟你说过了嘛?你配置问题,部署到IIS上,需要修改Silverlight端的服务配置文件。
注意下面红色部分,endpoint不能带端口号。

Silverlight客户端:
<configuration>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="CustomBindi……
[/Quote]

嗯。谢谢您。

string weburl = Application.Current.Host.Source.ToString();
weburl = weburl.Substring(0, (weburl.Length - 23)) + "/ChartsService.svc";
MyChartsService.ChartsServiceClient client = new MyChartsService.ChartsServiceClient("CustomBinding_ChartsService1", weburl);

这样写就好了。



但是还想再请教下。
1、跨域到底指的是什么?

2、“clientaccesspolicy.xml”和“crossdomain.xml”分别有什么作用?

3、
<endpoint address="http://localhost:2686/Mycems.UI/ChartsService.svc"
binding="customBinding" bindingConfiguration="CustomBinding_ChartsService"
contract="ChartsService.ChartsService" name="CustomBinding_ChartsService" />
<endpoint address="http://localhost:4707/Mycems.UI/ChartsService.svc"
binding="customBinding" bindingConfiguration="CustomBinding_ChartsService1"
contract="MyChartsService.ChartsService" name="CustomBinding_ChartsService1" />

为什么会有两个地址???
暖枫无敌 2012-03-24
  • 打赏
  • 举报
回复
之前不是跟你说过了嘛?你配置问题,部署到IIS上,需要修改Silverlight端的服务配置文件。
注意下面红色部分,endpoint不能带端口号

Silverlight客户端:
<configuration>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="CustomBinding_ChartsService">
<binaryMessageEncoding />
<httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
</binding>
<binding name="CustomBinding_ChartsService1">
<binaryMessageEncoding />
<httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://localhost:2686/Mycems.UI/ChartsService.svc"
binding="customBinding" bindingConfiguration="CustomBinding_ChartsService"
contract="ChartsService.ChartsService" name="CustomBinding_ChartsService" />
<endpoint address="http://localhost:4707/Mycems.UI/ChartsService.svc"
binding="customBinding" bindingConfiguration="CustomBinding_ChartsService1"
contract="MyChartsService.ChartsService" name="CustomBinding_ChartsService1" />
</client>
</system.serviceModel>
</configuration>

========================》
Silverlight客户端:
<configuration>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="CustomBinding_ChartsService">
<binaryMessageEncoding />
<httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
</binding>
<binding name="CustomBinding_ChartsService1">
<binaryMessageEncoding />
<httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://localhost/Mycems.UI/ChartsService.svc"
binding="customBinding" bindingConfiguration="CustomBinding_ChartsService"
contract="ChartsService.ChartsService" name="CustomBinding_ChartsService" />
<endpoint address="http://localhost/Mycems.UI/ChartsService.svc"
binding="customBinding" bindingConfiguration="CustomBinding_ChartsService1"
contract="MyChartsService.ChartsService" name="CustomBinding_ChartsService1" />
</client>
</system.serviceModel>
</configuration>

同时选中Silverlight端的那个服务,右键,选择“配置服务”,将上面的服务地址后面的端口号,去掉即可。
如果还不行的话,留下你的QQ,我来帮你搞定。
laichunlin 2012-03-24
  • 打赏
  • 举报
回复
在siliverlight中你添加服务了吗?

在客户端中添加服务然后会自动生成代理类

这个代理类包含你写的wcf中所有的方法

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧