此服务的WCF元数据发布当前已禁用+内容类型错误

时间:2011-02-07 02:58:05

标签: .net wcf

当我在浏览器中浏览服务时,我得到的元数据错误。我不是在用客户端消费它

和是..我添加了<serviceMetadata httpGetEnabled="True"/>,我有一个mex端点定义

但它仍然不起作用..

所以我创建了一个在IIS7上托管的准系统服务。全新安装Windows 7和VS2010。

我按照本页的说明写了这封信:

http://msdn.microsoft.com/en-us/library/ms733766.aspx

我确信这必须是IIS7的某种配置问题但不确定。这是我的服务设置:

编辑:

我尝试使用svcutil访问该服务并收到以下错误:

The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..

它还说:The HTML document does not contain Web service discovery information.

不确定如何解决它,但是..

.svc文件:

<%@ServiceHost language="C#" Debug="true" Service="DestructionServices.TacticalNukeSVC“%&GT;

.cs文件(位于C:\ Development \ HostedDestructionServices \ App_Code文件夹中):

using System;
using System.ServiceModel;

namespace DestructionServices
{
    [ServiceContract]
    public interface INukeInterface
    {
        [OperationContract]
        string FireMissile();

        [OperationContract]
        string DirectFire(double x, double y, double z);

        [OperationContract]
        void EnterCoordinates(double x, double y, double z);
    }

    public class TacticalNukeSVC : INukeInterface
    {
        public string FireMissile()
        {
            return "Boom";
        }

        public void EnterCoordinates(double x, double y, double z)
        {
            //bah, who cares about coordinates..
        }

        public string DirectFire(double x, double y, double z)
        {
            return "Fired at: " + x + ", " + y + ", " + z;
        }
    }
}

Web.Config中:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="DestructionServices.Destro" behaviorConfiguration="MetadataBehavior">
        <endpoint address="" binding="wsHttpBinding" contract="DestructionServices.INukeInterface" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MetadataBehavior">
          <serviceDebug includeExceptionDetailInFaults="True" httpHelpPageEnabled="True" />
          <serviceMetadata httpGetEnabled="True"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

IIS

6 个答案:

答案 0 :(得分:70)

您的代码和配置似乎没问题 - 除了一点:

<service>标记中,您定义的名称似乎与实际实施服务的类不对应:

<service name="DestructionServices.Destro"  ......>
               ************************** 

但你的班级是:

namespace DestructionServices
{
    .....
    public class TacticalNukeSVC : INukeInterface
    {

这些名字需要匹配! config name=标记上的<service>属性必须,与您的服务类完全相同 - 完全限定,包括命名空间 - 所以在这种情况下,它应该是:

<service name="DestructionServices.TacticalNukeSVC" ......>

答案 1 :(得分:2)

之前使用nice~setting的WCF工作已停止工作并显示 - 错误 - 此服务的元数据发布当前已禁用。

THOUGH MEX设置很完美,WCF仍显示上述错误,原因:从VS IDE创建的虚拟目录未创建,但它提供了成功&#34;消息..

只需手动在IIS中创建虚拟目录,就可以解决宾果错误。

希望它有所帮助!

答案 2 :(得分:0)

遇到类似的问题。我在web.config中的服务标记中使用了错误的命名空间,而不是svc文件中服务类的命名空间。

的web.config

< service name="X.Y.Z.ContentService" behaviorConfiguration="XServiceBehavior">

svc文件

<%@ ServiceHost Language="C#" Debug="true" Service="X.Y.A.ContentService" %>

如上所示,web.config中的服务标签具有名称空间X.Y.Z,其中svc文件具有X.Y.A。

(感谢Marc)

答案 3 :(得分:0)

我有另一个问题。我有一个IIS asmx应用程序,在里面我已经放置了一个带有svc的子文件夹。配置正确,但直到我在目录中的web.config中找到它时才给我元数据:

<system.web>
  <webServices>
    <soapExtensionTypes>
      <add type="SPFWebService.SPFWebServiceExtension,App_Code" priority="1" group="0" />
    </soapExtensionTypes>
  </webServices>
</system.web>

通过将我的新服务移至单独的目录来修复它。

答案 4 :(得分:0)

如果你有一个没有默认构造函数的类和另一个构造函数,那么添加一个空的默认构造函数,我有同样的问题,我解决了它。

答案 5 :(得分:0)

我有类似的问题。对于任何可能在以后遇到此问题的人。我的问题是我的服务接口没有[ServiceContract] DataAnnotation

[ServiceContract] //<--This was missing
public interface IServiceInterface
{
    [OperationContract]
    void Foo(Bar bar)
    //...
}