.net 此服务的 WCF 元数据发布当前已禁用 + 内容类型错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4917761/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WCF Metadata publishing for this service is currently disabled + Content Type error
提问by KevinDeus
That Metadata error is what I get when I browse to the service in a browser. I am not consuming it with a client
当我在浏览器中浏览到服务时,我得到了元数据错误。我没有和客户一起消费
and Yes.. I added <serviceMetadata httpGetEnabled="True"/>, and I have a mex endpoint defined
是的..我添加了<serviceMetadata httpGetEnabled="True"/>,我定义了一个 mex 端点
but it still won't work..
但它仍然不起作用..
So I created a barebones service to host on IIS7. Fresh install of Windows 7 and VS2010.
所以我创建了一个准系统服务来托管在 IIS7 上。全新安装 Windows 7 和 VS2010。
I had followed the instructions of this page to the letter:
我已按照此页面的说明进行操作:
http://msdn.microsoft.com/en-us/library/ms733766.aspx
http://msdn.microsoft.com/en-us/library/ms733766.aspx
I'm convinced that this has to be some sort of configuration issue with IIS7 but and not sure. Here's my service setup:
我确信这一定是 IIS7 的某种配置问题,但不确定。这是我的服务设置:
EDIT:
编辑:
I tried accessing the service with svcutil and got the following error:
我尝试使用 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'..
it also says: The HTML document does not contain Web service discovery information.
它还说: The HTML document does not contain Web service discovery information.
not sure how to resolve it, however..
不知道如何解决它,但是..
.svc file:
.svc 文件:
<%@ServiceHost language="C#" Debug="true" Service="DestructionServices.TacticalNukeSVC"%>
<%@ServiceHost language="C#" Debug="true" Service="DestructionServices.TacticalNukeSVC"%>
.cs file (located in the C:\Development\HostedDestructionServices\App_Code folder):
.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>


回答by marc_s
Your code and config seems fine - except for one little point:
您的代码和配置似乎很好 - 除了一点点:
In your <service>tag, you have defined a name that doesn't seem to correspond to the class that actually implements your service:
在您的<service>标签中,您定义了一个似乎与实际实现您的服务的类不对应的名称:
<service name="DestructionServices.Destro" ......>
**************************
but your class is:
但你的班级是:
namespace DestructionServices
{
.....
public class TacticalNukeSVC : INukeInterface
{
Those names need to match! The name=attribute on the <service>tag in config must beexactly what your service class is called - fully qualified, including namespace - so in your case here, it should be:
这些名字需要匹配!在name=该属性<service>的配置标签必须什么服务类被称为-完全合格,其中包括命名空间-所以你的情况在这里,它应该是:
<service name="DestructionServices.TacticalNukeSVC" ......>
回答by HydTechie
Previously working WCF with nice~ settings stopped working and shows - error- Metadata publishing for this service is currently disabled.
以前使用 nice~ 设置工作的 WCF 停止工作并显示 - 错误 - 此服务的元数据发布当前已禁用。
THOUGH MEX Settings are perfect, still WCF shows above error, reason: The virtual directory created from VS IDE IS NOT Created, though it gives "success" message..
虽然 MEX 设置是完美的,但 WCF 仍然显示上述错误,原因:未创建从 VS IDE 创建的虚拟目录,尽管它给出了“成功”消息..
Just Create Virtual Directory in IIS manually , Bingo error is resolved.
只需在 IIS 中手动创建虚拟目录,Bingo 错误已解决。
Hope it helps!
希望能帮助到你!
回答by evilkos
I had another issue. I have an IIS asmx application, and inside I've placed a subfolder with svc. Configured it properly, but it didn't give me the metadata until I found this in web.config in parentdirectory:
我有另一个问题。我有一个 IIS asmx 应用程序,在里面我已经放置了一个带有 svc 的子文件夹。正确配置了它,但直到我在父目录中的 web.config 中找到它之前它没有给我元数据:
<system.web>
<webServices>
<soapExtensionTypes>
<add type="SPFWebService.SPFWebServiceExtension,App_Code" priority="1" group="0" />
</soapExtensionTypes>
</webServices>
</system.web>
Fixed it by removing my new service to a separate directory.
通过将我的新服务删除到单独的目录来修复它。
回答by Ahmad Abu Ghoush
if you have a class with no default constructor an another constructors , then add an empty default constructor , I had the same issue and i resolved it by this .
如果你有一个没有默认构造函数和另一个构造函数的类,然后添加一个空的默认构造函数,我有同样的问题,我通过这个解决了它。
回答by nrpadilla2
I had a similar issue. For anyone that might come across this later. My problem was that my service interface did not have the [ServiceContract] DataAnnotation
我有一个类似的问题。对于以后可能会遇到此问题的任何人。我的问题是我的服务接口没有 [ServiceContract] DataAnnotation
[ServiceContract] //<--This was missing
public interface IServiceInterface
{
[OperationContract]
void Foo(Bar bar)
//...
}
回答by AIyer
Encountered a similar issue. I had the wrong namespace in my service tag in web.config as against the namespace for the service class in the svc file.
遇到了类似的问题。我在 web.config 中的服务标记中的命名空间与 svc 文件中服务类的命名空间相反。
web.config
网页配置
< service name="X.Y.Z.ContentService" behaviorConfiguration="XServiceBehavior">
svc file
.svc 文件
<%@ ServiceHost Language="C#" Debug="true" Service="X.Y.A.ContentService" %>
As seen above, service tag in web.config had namespace X.Y.Z where the svc file had X.Y.A.
如上所示,web.config 中的服务标签具有命名空间 XYZ,其中 svc 文件具有 XYA
(Thanks to Marc)
(感谢马克)

