在 Silverlight 中使用 netTcpBinding
我创建了一个在 IIS 7 中托管的 WCF 服务
我的 .NET 版本是 4.0
我的操作系统是 Windows 7 Ultimate
我的服务地址:
- net.tcp://localhost:4504/WPFHost/tcp
当我添加服务引用时,我收到两个警告:
第一:
Warning 2 Custom tool warning: Endpoint 'NetTcpBinding_IChat' at address 'net.tcp://localhost:4504/WPFHost/tcp' is not compatible with Silverlight 4. Skipping... D:\Projects\C#\WCF\SilverlightApplication1\SilverlightApplication1\Service References\SV\Reference.svcmap 1 1 SilverlightApplication1
第二:
Warning 3 Custom tool warning: No endpoints compatible with Silverlight 4 were found. The generated client class will not be usable unless endpoint information is provided via the constructor. D:\Projects\C#\WCF\SilverlightApplication1\SilverlightApplication1\Service References\SV\Reference.svcmap 1 1 SilverlightApplication1
我的服务Appconfig文件如下:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
<system.serviceModel>
<services>
<service name="WCFService.Service"
behaviorConfiguration="behaviorConfig">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:4504/WPFHost/"/>
<add baseAddress="http://localhost:4505/WPFHost/"/>
</baseAddresses>
</host>
<endpoint address="tcp"
binding="netTcpBinding"
bindingConfiguration="tcpBinding"
contract="WCFChatLibrary.IChat"/>
<endpoint address="net.tcp://localhost:4503/WPFHost/mex"
binding="mexTcpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="behaviorConfig">
<serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceThrottling maxConcurrentCalls="100" maxConcurrentSessions="100"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="tcpBinding"
maxBufferSize="67108864"
maxReceivedMessageSize="67108864"
maxBufferPoolSize="67108864"
transferMode="Buffered"
closeTimeout="00:00:10"
openTimeout="00:00:10"
receiveTimeout="00:20:00"
sendTimeout="00:01:00"
maxConnections="100">
<security mode="None">
</security>
<readerQuotas maxArrayLength="67108864"
maxBytesPerRead="67108864"
maxStringContentLength="67108864"/>
<reliableSession enabled="true" inactivityTimeout="00:20:00"/>
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
</configuration>
当我调用服务时,它抛出异常。这是我的代码:
if (this.proxy == null)
{
try
{
this.StatusTxtBlock.Text = "Ready";
this.localClient = new Client();
this.localClient.Username = "User-" + Guid.NewGuid();
this.proxy = new ChatClient(new InstanceContext(this));
this.proxy.OpenAsync();
this.proxy.ConnectAsync(this.localClient);
this.proxy.ConnectCompleted += new EventHandler<ConnectCompletedEventArgs>(proxy_ConnectCompleted);
}
catch (Exception ex)
{
this.StatusTxtBlock.Text = "Exception: "+ ex.Message;
}
}
例外是:
Exception: The given key was not present in the dictionary
我遵循这个 教程但不走运,
我不知道该怎么办,我的头脑和视野一片空白,也许我要疯了。请有人救救我(我的意思是帮助我)。
I Have created a WCF service that hosted in IIS 7
My .NET version is 4.0
My Operating System is Windows 7 Ultimate
My Service Address:
- net.tcp://localhost:4504/WPFHost/tcp
When i added service reference i get two warning:
First:
Warning 2 Custom tool warning: Endpoint 'NetTcpBinding_IChat' at address 'net.tcp://localhost:4504/WPFHost/tcp' is not compatible with Silverlight 4. Skipping... D:\Projects\C#\WCF\SilverlightApplication1\SilverlightApplication1\Service References\SV\Reference.svcmap 1 1 SilverlightApplication1
Second:
Warning 3 Custom tool warning: No endpoints compatible with Silverlight 4 were found. The generated client class will not be usable unless endpoint information is provided via the constructor. D:\Projects\C#\WCF\SilverlightApplication1\SilverlightApplication1\Service References\SV\Reference.svcmap 1 1 SilverlightApplication1
My service Appconfig file is like below:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
<system.serviceModel>
<services>
<service name="WCFService.Service"
behaviorConfiguration="behaviorConfig">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:4504/WPFHost/"/>
<add baseAddress="http://localhost:4505/WPFHost/"/>
</baseAddresses>
</host>
<endpoint address="tcp"
binding="netTcpBinding"
bindingConfiguration="tcpBinding"
contract="WCFChatLibrary.IChat"/>
<endpoint address="net.tcp://localhost:4503/WPFHost/mex"
binding="mexTcpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="behaviorConfig">
<serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceThrottling maxConcurrentCalls="100" maxConcurrentSessions="100"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="tcpBinding"
maxBufferSize="67108864"
maxReceivedMessageSize="67108864"
maxBufferPoolSize="67108864"
transferMode="Buffered"
closeTimeout="00:00:10"
openTimeout="00:00:10"
receiveTimeout="00:20:00"
sendTimeout="00:01:00"
maxConnections="100">
<security mode="None">
</security>
<readerQuotas maxArrayLength="67108864"
maxBytesPerRead="67108864"
maxStringContentLength="67108864"/>
<reliableSession enabled="true" inactivityTimeout="00:20:00"/>
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
</configuration>
When i call the service it throw exception. Here is my code:
if (this.proxy == null)
{
try
{
this.StatusTxtBlock.Text = "Ready";
this.localClient = new Client();
this.localClient.Username = "User-" + Guid.NewGuid();
this.proxy = new ChatClient(new InstanceContext(this));
this.proxy.OpenAsync();
this.proxy.ConnectAsync(this.localClient);
this.proxy.ConnectCompleted += new EventHandler<ConnectCompletedEventArgs>(proxy_ConnectCompleted);
}
catch (Exception ex)
{
this.StatusTxtBlock.Text = "Exception: "+ ex.Message;
}
}
and the exception is:
Exception: The given key was not present in the dictionary
I follow this tutorial but no luck
I don't know what to do, my mind and vision is going to blank, maybe i'm going crazy. Please somebody save me (i mean help me).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Silverlight 4 支持服务器上的
NetTcpBinding
子集。例如,它不支持安全性(这适合您的情况,因为您的绑定中有
),而且它也不支持可靠消息传递(这可能是您的情况的问题,因为您在绑定中启用了它)。这是与 SL 兼容的netTcpBinding
的一种绑定配置:Silverlight 4 supports a subset of
NetTcpBinding
on the server. It doesn't support security, for example (which is fine for your case, since you have<security mode="None">
in your binding), and it also doesn't support reliable messaging (which is likely the problem in your case, since you have it enabled in your binding). This is one binding configuration fornetTcpBinding
which is compatible with SL:这篇 MSDN 文章指出
NetTcpBinding
不能与 Silverlight 4 一起使用。我不确定是否相信 Tomasz Janczuk 还是 MSDN,但 Tomasz 的文章已经有 2 年历史了,所以我的猜测是:
NetTcpBinding
计划用于 Silverlight 4,但最终没有包含在内。您可以考虑切换到
BasicHttpBinding
或“自行部署”自定义绑定,如 以下文章。This MSDN article states that
NetTcpBinding
cannot be used with Silverlight 4.I'm not sure whether to believe Tomasz Janczuk or MSDN, but Tomasz's article is 2 years old, so my guess is:
NetTcpBinding
was planned for Silverlight 4 but not included in the end.You can consider switching to
BasicHttpBinding
or 'roll your own' custom binding as described in the following article.