0

WCF 的配置最近一直是个祸根。我有以下配置:

  <system.serviceModel>

    <!-- Set up Custom Behaviors -->
    <behaviors>

      <endpointBehaviors>
        <behavior name="jsonBehavior">
          <enableWebScript />
        </behavior>
      </endpointBehaviors>


      <serviceBehaviors>
        <behavior name="WebPostService.Service1Behavior">
          <serviceMetadata   httpGetEnabled="true"  />
          <!-- -->
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>


    </behaviors>


    <!-- Set up the binding configuration  -->
    <bindings>

      <basicHttpBinding>
        <binding name="SOAPBinding">
          <security mode="None">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </basicHttpBinding>

      <webHttpBinding>
        <binding name="JSONBinding"
                 hostNameComparisonMode="StrongWildcard"
                 receiveTimeout="00:10:00"
                 sendTimeout="00:10:00"
                 openTimeout="00:10:00"
                 closeTimeout="00:10:00"
                 maxReceivedMessageSize="1000000"
                 maxBufferPoolSize="2000000"
                 bypassProxyOnLocal="false"
                 useDefaultWebProxy="true" >
          <security mode="None">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </webHttpBinding>


    </bindings>

    <services>


      <service behaviorConfiguration="WebPostService.Service1Behavior"
               name="WebPostService.WebPostSvc"
      >

        <endpoint address="soap"
                  binding="basicHttpBinding"
                  bindingConfiguration="SOAPBinding"
                  contract="WebPostService.IWebPostSvc"
        />

        <endpoint address="json"
                  binding="webHttpBinding"
                  bindingConfiguration="JSONBinding"
                  behaviorConfiguration="jsonBehavior"
                  contract="WebPostService.IWebPostSvc"

        />

        <!--    -->
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="System.ServiceModel.Description.IMetadataExchange"
        />

      </service>

    </services>

  </system.serviceModel>

为什么我会收到以下错误?:该错误似乎是个谜,因为该合同可作为 .NET Framework 的一部分使用。我正在使用 .NET 3.5。

[InvalidOperationException: The contract name 'System.ServiceModel.Description.IMetadataExchange' could not be found in the list of contracts implemented by the service 'WebPostSvc'.]
   System.ServiceModel.Description.ConfigLoader.LookupContract(String contractName, String serviceName) +11679727
   System.ServiceModel.Description.ConfigLoader.LoadServiceDescription(ServiceHostBase host, ServiceDescription description, ServiceElement serviceElement, Action`1 addBaseAddress) +11678779
   System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader configLoader, ServiceDescription description, ServiceElement serviceSection) +55
   System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader configLoader, ServiceDescription description, String configurationName) +35
   System.ServiceModel.ServiceHostBase.ApplyConfiguration() +69
   System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses) +190
   System.ServiceModel.ServiceHost.InitializeDescription(Type serviceType, UriSchemeKeyedCollection baseAddresses) +32
   System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses) +139
   System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(Type serviceType, Uri[] baseAddresses) +28
   System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +331
   System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +11729164
   System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +42
   System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +479

[ServiceActivationException: The service '/WebPostSvc.svc' cannot be activated due to an exception during compilation.  The exception message is: The contract name 'System.ServiceModel.Description.IMetadataExchange' could not be found in the list of contracts implemented by the service 'WebPostSvc'..]
   System.ServiceModel.AsyncResult.End(IAsyncResult result) +11599786
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +194
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, Boolean flowContext) +176
   System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e) +278
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
4

1 回答 1

0

您不需要合同中的全名,只需使用

 <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
于 2012-07-02T14:17:54.423 回答