此服务的 WCF 元数据发布当前已禁用 + 内容类型错误 [英] WCF Metadata publishing for this service is currently disabled + Content Type error

查看:31
本文介绍了此服务的 WCF 元数据发布当前已禁用 + 内容类型错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

那个元数据错误是我在浏览器中浏览到服务时得到的.我没有和客户一起消费

That Metadata error is what I get when I browse to the service in a browser. I am not consuming it with a client

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

and Yes.. I added <serviceMetadata httpGetEnabled="True"/>, and I have a mex endpoint defined

但是还是不行..

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

So I created a barebones service to host on IIS7. Fresh install of Windows 7 and VS2010.

我已按照此页面的说明进行操作:

I had followed the instructions of this page to the letter:

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

我确信这一定是 IIS7 的某种配置问题,但不确定.这是我的服务设置:

I'm convinced that this has to be some sort of configuration issue with IIS7 but and not sure. Here's my service setup:

我尝试使用 svcutil 访问该服务,但出现以下错误:

I tried accessing the service with svcutil and got the following error:

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'..

它还说:HTML 文档不包含 Web 服务发现信息.

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

not sure how to resolve it, however..

.svc 文件:

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

.cs 文件(位于 C:DevelopmentHostedDestructionServicesApp_Code 文件夹中):

.cs file (located in the C:DevelopmentHostedDestructionServicesApp_Code folder):

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:

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>

推荐答案

你的代码和配置看起来不错 - 除了一点点:

Your code and config seems fine - except for one little point:

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

In your <service> tag, you have defined a name that doesn't seem to correspond to the class that actually implements your service:

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

但你的班级是:

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

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

Those names need to match! The name= attribute on the <service> tag in config must be exactly what your service class is called - fully qualified, including namespace - so in your case here, it should be:

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

这篇关于此服务的 WCF 元数据发布当前已禁用 + 内容类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆