【问题标题】:Metadata contains a reference that cannot be resolved for iis hosted wcf service元数据包含无法为 iis 托管的 wcf 服务解析的引用
【发布时间】:2011-07-19 14:40:03
【问题描述】:

任何帮助都会得到帮助 我有一个示例服务和一个测试控制台应用程序 我通过将来自相同解决方案的引用添加到控制台 appln 来访问示例服务元数据,并且我正在获取绑定信息。 我也在 IIS 中托管(发布)相同的服务,并通过测试控制台 appln 中的服务 URL 添加引用,我正在获取结果。

现在的问题是我在 IIS 中运行的托管(发布)数据服务,我正在添加引用并尝试从服务 URL 读取元数据,这给了我错误。 元数据包含无法解析的引用:'http://localhost:9092/TransactionDataService.svc/mex'

我在两种情况下都使用 mexhttpbinding 和 multiplebingind = true(示例 + 我正在运行的数据服务)

示例服务的网络配置

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="ServiceApp.Service1">
        <endpoint address="" binding="wsHttpBinding" name="Service1Endpoint" contract="ServiceApp.IService1"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

用于访问元数据的代码

EndpointAddress serviceEndpointAddress = new EndpointAddress("http://localhost:30617/Service1.svc/mex");

            var endpointCollection = MetadataResolver.Resolve(typeof(IService1), serviceEndpointAddress);


            foreach (var endpoint in endpointCollection)
            {
                Type bindingType = endpoint.Binding.GetType();

                if (bindingType.Equals(typeof(WSHttpBinding)))
                {
                    Console.WriteLine("Eureka!!!");
                }
            }

数据服务的网络配置

<bindings>
            <wsHttpBinding>
                <binding name="WSHttp" openTimeout="01:00:00" closeTimeout="01:00:00" sendTimeout="01:00:00" receiveTimeout="01:00:00" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="0" maxReceivedMessageSize="2147483647">
          <reliableSession enabled="true" />
                    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
                </binding>
            </wsHttpBinding>
        </bindings>

    <!--Service Behaviors-->
        <behaviors>
            <serviceBehaviors>
                <behavior name="DataAccessBehavior">
                    <dataContractSerializer maxItemsInObjectGraph="2147483647" />
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="true" />
                </behavior>
            </serviceBehaviors>
        </behaviors>

    <!--Service Configuration-->
        <services>
            <service name="TransactionDataAccess" behaviorConfiguration="DataAccessBehavior">
                <endpoint name="DataAccessServiceEndpoint" address="" binding="wsHttpBinding" bindingConfiguration="WSHttp" contract="TransactionDataServices.ITransactionDataService"/>
        <endpoint address="mex" binding="wsHttpBinding" contract="IMetadataExchange"/>
            </service>
        </services>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
        <directoryBrowse enabled="true" />
    </system.webServer>

访问数据服务元数据的代码是相同的,除了服务网址

【问题讨论】:

    标签: wcf wcf-binding


    【解决方案1】:

    看看你是否忘记用[DataContract]属性装饰你的传输类(不要忘记[DataMember])。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多