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

Kev*_*eus 32 .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'..
Run Code Online (Sandbox Code Playgroud)

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

不知道如何解决它,但..

.svc文件:

<%@ServiceHost language="C#" Debug="true" Service="DestructionServices.TacticalNukeSVC"%>

.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;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

IIS

mar*_*c_s 70

您的代码和配置似乎很好 - 除了一点:

在您的<service>标记中,您定义了一个名称,该名称似乎与实际实现您的服务的类不对应:

<service name="DestructionServices.Destro"  ......>
               ************************** 
Run Code Online (Sandbox Code Playgroud)

但是你的班级是:

namespace DestructionServices
{
    .....
    public class TacticalNukeSVC : INukeInterface
    {
Run Code Online (Sandbox Code Playgroud)

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

<service name="DestructionServices.TacticalNukeSVC" ......>
Run Code Online (Sandbox Code Playgroud)

  • 就是这样.谢谢马克.:) (3认同)