【问题标题】:Communication between two WCF Services in selfhosting Server自托管服务器中两个 WCF 服务之间的通信
【发布时间】:2013-03-01 10:22:22
【问题描述】:

MSDN article 中描述的自托管服务中 有两个服务。

现在我想打电话给对方。一个做一些与数据库相关的工作,另一个提供一些工作。我想在其他服务中使用数据库功能。

我尝试添加此处提到的服务引用:Stackoverflow with similar question 但我收到消息:“从地址下载元数据时出错”, 因此无法添加服务引用。

服务本身都在运行和工作,因为我已经在客户端应用程序中使用它们。

这是我要使用的服务中的 web.config。

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

以下是我的自托管服务中 App.config 的部分内容

<?xml version="1.0"?>
<configuration>

  <system.serviceModel>

   <!-- omitted lots of blocks -->

    <services>

      <service name="MyProject.WorkService.GeneralWorkService" behaviorConfiguration="SimpleServiceBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/"/>
          </baseAddresses>
        </host>
        <endpoint address="traceability" binding="basicHttpBinding" name="WorkService" contract="MyProject.Service2.Contracts.IService2"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

      </service>
      <service name="MyProject.DatabaseService.GeneralDatabaseService" behaviorConfiguration="SimpleServiceBehavior">
          <host>
            <baseAddresses>
              <add baseAddress="http://localhost:8000/"/>
            </baseAddresses>
          </host>
          <endpoint address="gateway" binding="basicHttpBinding" name="DatabaseService" contract="MyProject.DatabaseService.Contracts.IDatabaseService"/>
          <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>

    </services>
    <client>
      <endpoint name="Service2EP" address="http://localhost/someWork" binding="basicHttpBinding" contract="MyProject.Service2.IService2">        
      </endpoint>

      <endpoint name="DatabaseServiceEP" address="http://localhost/gateway" binding="basicHttpBinding" contract="MyProject.DatabaseService.IDatabaseService">
      </endpoint>



    </client>
  </system.serviceModel>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>

-更新-

我可以使用浏览器窗口查看我的服务

http://localhost:8000

也许还有其他方式可以使用我的服务。我应该使用一些代理吗 可以用svcutil生成?

也许有更好的方法。添加服务参考似乎不起作用 我也说不出为什么。

【问题讨论】:

  • 你能把代码贴出来,你从客户端服务调用服务器服务的地方吗?
  • 我没有代码,因为这是我想要实现的目标

标签: c# wcf service self-hosting


【解决方案1】:

您确定在您尝试引用的服务的配置中配置了 mex-endpoint 吗? 如果您没有,该服务将不会公开所需的信息 (WSDL) 以进行服务引用...。

【讨论】:

  • 我已经在自托管 exe 中定义了它。可能这还不够,去试试吧
  • 还要确保您的服务正在运行您尝试添加的 ATM,
  • 在“添加服务引用”对话框中选择“发现”后单击“确定”时服务启动。
【解决方案2】:

至少有4种可能性:

  • 元数据交换 mex 端点未定义
  • 元数据交换未启用
  • 您使用了错误的地址
  • 您被某些安全设置阻止

来自There was an error downloading metadata from the address

【讨论】:

  • mex 在 selfhosting exe 中定义,服务本身没有定义端点。已经发布了代码。我已经使用 MEX 为我的客户生成代理。它工作正常
  • 如我所见,您在 GeneralWorkService 和 GeneralDatabaseService 中都有 。尝试更改“mex1”和“mex2”中的地址。我想当您启动服务时,您的两个 mex 点可能会发生冲突,因为它们都将具有名称 localhost:8080/mex。在 IIS 中,您的服务的完整路径由 IIS 本身生成,此示例可能在那里工作。但如果我没记错的话 - 自托管应用程序只是将您的基本地址与您的端点地址结合起来,而不需要修改它们
  • 已经改了,但这没什么区别。
【解决方案3】:

终于找到答案了。

必须将端点从自托管 app.config 复制到服务 web.config。

从那时起,对话框中的错误消息(链接底部的“详细信息”) 很有帮助。

只需将服务行为添加到我已经在 selfhosting app.config 中定义的 DatabaseService。

感谢大家的帮助。将接受 W1ck3dHcH 的回答,因为它是正确的,但我只是没有看到它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-30
    • 2013-04-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多