Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
572 views
in Technique[技术] by (71.8m points)

.net - WCF Metadata publishing for this service is currently disabled + Content Type error

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

but it still won't work..

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

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

EDIT:

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

it also says: The HTML document does not contain Web service discovery information.

not sure how to resolve it, however..

.svc file:

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

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

<?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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 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 be exactly what your service class is called - fully qualified, including namespace - so in your case here, it should be:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...