WCF问题及解决方案

1、Binding Security 2009.03.26

 问题现象:部分客户端无法调用WCF服务

 引起原因:服务绑定设置了安全设定,但并未正确设置安全配置。

 解决方案:要想不搞复杂的安全配置,将security mode="None"。如下:

<bindings>
      
<netTcpBinding>
        
<binding xxxxx />
          
<security mode="None" />
        
</binding>
      
</netTcpBinding>
</bindings>



2、Session 2009.04.02

问题现象:

调用服务后,客户端弹出以下错误:The request to create a reliable session has been refused by the RM Destination. Server'xxx' is too busy to process this request.Try again later. The channel could not be opened.

引起原因:

服务端用了session模式,客户端代理每启动一次将在服务端建立一个session。服务允许建立的session数量是有限的,当达到上限时就会出现上述现象。

解决方案:

退出程序时,一定要调用Proxy的Close方法,会引起WCF自动关闭该代理建立起来的session 。这样session才不会一直增长下去。另外,调试程序时,由于在VS下直接Stop Debug,并未点击应用程序的关闭按钮正常退出也不会调用Proxy的Close方法,也会造成session滞留服务端。

 

3、服务代理更新问题 2009.04.09

问题现象:

添加自编的服务引用或者更新服务引用的时候,服务能正常启动,测试客户端报错:

Error: Cannot obtain Metadata from http://localhost:6102/Services/TechDataMgtService/mex If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address.  For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error    URI: http://localhost:6102/Services/TechDataMgtService/mex    元数据包含无法解析的引用:“http://localhost:6102/Services/TechDataMgtService/mex”。    XML 文档(1, 99824)中有错误。    读取 XML 数据时,超出最大名称表字符计数配额 (16384)。名称表是用于存储在处理 XML 时所遇到的字符串的数据结构 - 具有非重复元素、属性名称和属性值的长 XML 文档可能会触发此配额。通过更改在创建 XML 读取器时所使用的 XmlDictionaryReaderQuotas 对象的 MaxNameTableCharCount 属性,可增加此配额。 第 1 行,位置为 99824。HTTP GET Error    URI: http://localhost:6102/Services/TechDataMgtService/mex    下载“http://localhost:6102/Services/TechDataMgtService/mex”时出错。    请求因 HTTP 状态 400 失败: Bad Request。

引起原因:

WCF 服务中的接口定义太多,超出了WCF默认的端口数据解析长度,默认是16384。另外还有一个可能的原因是在服务端的配置文件用了localhost,代理端在获取服务器的地址字符串后,解析出问题后(譬如长度超限)会尝试在本地的端口上再做解析。

解决方案:

如果客户端需要正确读取,则需要在客户端应用程序的Binding配置里将默认值maxNameTableCharCount="16384"改大,譬如2G
<!-- Reset maxStringContentLength for deserialize -->
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647"
              maxBytesPerRead
="2147483647" maxNameTableCharCount="2147483647" />

 但是VS2008自带的测试客户端Test Client(自动服务时自动启动的那个WcfTestClient.exe)就不能用了,因为我们改不了他的配置。

服务端的Binding配置同样也要改大。另外,服务端的配置文件不要用localhost,而改为服务器名称。

 

 4、IIS 元数据访问权限问题 2009.04.23

问题现象:

Server Error in '/CredentialsMgtService' Application.
--------------------------------------------------------------------------------

Failed to access IIS metabase.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.Hosting.HostingEnvironmentException: Failed to access IIS metabase.

The process account used to run ASP.NET must have read access to the IIS metabase (e.g. IIS://servername/W3SVC). For information on modifying metabase permissions, please see http://support.microsoft.com/?kbid=267904.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace:


[HostingEnvironmentException: Failed to access IIS metabase.]
   System.Web.Configuration.MetabaseServerConfig.MapPathCaching(String siteID, VirtualPath path) +637
   System.Web.Configuration.MetabaseServerConfig.System.Web.Configuration.IConfigMapPath2.MapPath(String siteID, VirtualPath vpath) +9
   System.Web.Hosting.HostingEnvironment.MapPathActual(VirtualPath virtualPath, Boolean permitNull) +174
   System.Web.Hosting.HostingEnvironment.MapPathInternal(VirtualPath virtualPath, Boolean permitNull) +51
   System.Web.CachedPathData.GetConfigPathData(String configPath) +341
   System.Web.CachedPathData.GetConfigPathData(String configPath) +234
   System.Web.CachedPathData.GetApplicationPathData() +38
   System.Web.CachedPathData.GetVirtualPathData(VirtualPath virtualPath, Boolean permitPathsOutsideApp) +8801967
   System.Web.Configuration.RuntimeConfig.GetLKGRuntimeConfig(VirtualPath path) +117
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053


引起原因:

在计算机上先安装.net Framework,后安装IIS,会导致该问题出现。

 

解决方案

微软的技术支持页面告诉了解决方法,就是:

第一步:

在 控制台进入$windows\Microsoft.NET\Framework\v2.0.50727的目录,运行

aspnet_regiis –ga <WindowsUserAccount>

目的向IIS注册运行数据存取服务的Windows帐户存取元数据的权限。

第二步:

aspnet_regiis -i

安装ASP.net 2.0版本并将所有应用程序池升级到ASP.NET 2.0版。忽略“ASP.NET 1.1”应用程序池。

 

5.  HTTP Error 404.3 - Not Found 2009.6.10

 问题现象:

 浏览一个基于IIS的服务时,提示以下错误:

 HTTP Error 404.3 - Not Found
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.

解决办法:

Windows Vista在安装了.netFramework 3.0后,需要在程序->打开或关闭Windows功能中的Microsoft.NET Framework 3.0中打开选项:Windows communication Foundation HTTP Activation 和 Windows communication Foundation Non-HTTP Activation。


6. TCP port 80 is being used by another application

问题现象:

HTTP could not register URL http://+:80/Temporary_Listen_Addresses/<guid>/ because TCP port 80 is being used by another application

 解决办法:

因为使用了wsDualHttp 双工通讯,

clientBaseAddress = "http://YOUR_CLIENT_MACHINE_NAME:8008/Client"

将服务和客户端的调用网站端口改为非80端口


 

 

 

posted @ 2009-04-02 15:43  cubean  阅读(5727)  评论(1编辑  收藏  举报