wcf配置问题(错误)

时间:2012-07-02 13:22:22

标签: wcf .net-3.5 wcf-binding

最近,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

1 个答案:

答案 0 :(得分:0)

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

即可
 <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />