使用WCFTestClient测试简单的WCF Web服务时出现的WCF错误

13
当我试图使用 "wcftestclient" 测试 AutoLotWCFService 时,我收到如下错误。我做错了什么?任何见解都将有所帮助。这是一个简单的 Web 服务,具有使用 wshttpbinding 的接口契约和服务中的实现。以下是长错误消息:Web.Config 文件有 2 个端点——一个用于 Web 服务本身,另一个用于元数据交换。它基本上都是默认的东西。如果需要,我可以包含代码——似乎我无法在这里附加文件。
Error: Cannot obtain Metadata from http://localhost/AutoLotWCFService/Service.svc
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/AutoLotWCFService/Service.svc
    Metadata contains a reference that cannot be resolved: 'http://localhost/AutoLotWCFService/Service.svc'.
    The remote server returned an unexpected response: (405) Method not allowed.
    The remote server returned an error: (405) Method Not Allowed.
    HTTP GET Error    URI: http://localhost/AutoLotWCFService/Service.svc
    The document at the url http://localhost/AutoLotWCFService/Service.svc was not recognized as a known document type.The error message from each known type may help you fix the problem:
    - Report from 'DISCO Document' is 'Name cannot begin with the '%' character, hexadecimal value 0x25. Line 1, position 2.'.
    - Report from 'WSDL Document' is 'There is an error in XML document (1, 2).' -Name cannot begin with the '%' character, hexadecimal value 0x25. Line 1, position 2.
    - Report from 'XML Schema' is 'Name cannot begin with the '%' character, hexadecimal value 0x25. Line 1, position 2.'.


你能否包含与服务相关的配置部分?没有这些部分很难确定正在发生什么。 - Bryant
服务契约(以及使用的任何数据契约)也会很有帮助。 - James Bender
将以下代码添加到您的服务器 Web 配置文件中指定的 <behavior> 下,然后将提供真实错误信息:<serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true"/>。 - user269170
5个回答

15

最近我尝试在IIS7下的Windows Vista笔记本电脑上托管WCF时遇到了这个问题。

我首先收到了以下错误提示:"HTTP Error 404.3 - Not Found",其中一个解决方案是“确保为当前页面映射了预期的处理程序”。

因此,我手动为.svc文件添加了一个处理程序,并将其定义为DiscoveryRequestHandler,以为这可能有所帮助。但这导致了上面描述的问题。

实际的解决方法是删除我添加的处理程序,并运行以下命令:

CD c:\windows\Microsoft.Net\Framework\v3.0\Windows Communication Foundation\
ServiceModelReg -i

这解决了我的问题,服务正常运行。我希望这能帮助你解决问题。我不能确定,但可能是因为我在开发笔记本电脑上安装各种包的顺序不同。


太棒了!这个方法非常有效。我遇到了404.17的问题,但是这个方法解决了它。 - Ralf de Kleine
这也解决了我的“方法不允许”错误。该服务可以在Visual Studio的内置Web服务器上运行,但无法在本地主机上的IIS上运行。现在它也可以在IIS上工作了。 - P a u l

1
如果安装组件无法正常工作,请尝试修复,这将卸载并重新安装。
"%WINDIR%\Microsoft.Net\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe" -r

0

请尝试检查服务标记中的service(name)是否与您的web.config文件中的service(name)匹配(在servicename.svc上右键单击)。

祝好!


0

谢谢;信不信由你,至少通过wcftestclient加载服务的问题已经在我使用aspnet-regiis重新注册ASPNET到IIS时得到解决。

下一个问题是能否通过wcftestclient调用服务公开的方法。我必须启用Windows身份验证的匿名登录,但仍然会生成指向访问违规相关内容的异常。当搜索一些内容时,一些东西指向安装证书以便能够调用.. 如果可能请指点。


0

你需要确保服务行为配置启用了具有 httpGetEnabled="true" 的元数据标记。

<serviceBehaviors>
  <behavior name="serviceBehavior">
    <serviceMetadata httpGetEnabled="true">
  </behavior>
</serviceBehaviors>

此外,请确保您的服务引用了该行为。

<service name="blah" behaviorConfiguration="serviceBehavior">

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接