【问题标题】:Building WCF Service library in MS Web Developer 2010 Express在 MS Web Developer 2010 Express 中构建 WCF 服务库
【发布时间】:2012-03-06 19:08:26
【问题描述】:

我在 MS Web Developer 2010 Express 中创建了 WCF 服务库,其中 ITestSerivce 作为服务合同并提供了以下 Web.config 配置。但我收到这个错误 : 错误:无法从http://localhost:56016/TestService.svc 获取元数据 : 我不明白为什么网址是http://localhost:56016,而基地址是http://localhost:8001

谁能帮我解决这个问题。

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service behaviorConfiguration="ServiceBehavior" name="TestService">
        <host>
          <baseAddresses>
            <add baseAddress ="http://localhost:8001/" />
          </baseAddresses>
        </host>
        <endpoint address="" binding="wsHttpBinding" contract="ITestService"/>          
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <!--Setting httpGetEnabled you can publish the metadata -->
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="True" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <wsHttpBinding>
        <binding name="SampleServiceBinding">
          <security/>
        </binding>
      </wsHttpBinding>
    </bindings>
  </system.serviceModel>
</configuration>

【问题讨论】:

    标签: wcf


    【解决方案1】:

    上面的配置有一些问题。

    1. 服务元素的名称属性不是完全限定名称。

    2. endpoint 元素的合同属性值不是完全限定名称。

    一个完全限定的名字如下所示:

    MyWCFService.TestService (i.e. namespace.ServiceName)
    

    如果您在 Cassini Web 服务器上运行相同的内容,请右键单击属性并在 Web 选项卡下确保选中“用户 Visual Studio 开发服务器”选项并且未选中“自动分配端口”选项。而是选择“特定端口”并使用 8001 来匹配您的配置

    【讨论】:

    【解决方案2】:

    &lt;baseAddresses&gt; 配置仅用于self-hosted 服务+应用程序,IIS/WAS 不使用。 除非您使用诸如无文件激活 (article here) 之类的功能,否则您将 .svc 在您的 Web 服务器/站点上“放置”的位置定义了它的 URL。

    您的 IIS 网址将类似于

    http://localhost:8001/MyApp/TestService.svc?wsdl

    我不确定为什么 WCF 测试客户端默认使用错误的 URL - 只需输入正确的 URL,它就会缓存它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      • 2012-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-06
      相关资源
      最近更新 更多