2013-03-01 94 views
0

在此MSDN article 中描述的自托管服务中,有两个服务。在自托管中的两个WCF服务之间的通信服务器

现在我想打另一个。一个做一些数据库相关的东西,另一个提供一些工作。我想在其他服务中使用数据库功能。

我尝试添加服务引用这里提到: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> 

这里是从我的selfhosting服务从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> 

-update-

我可以用一个浏览器窗口中看到

http://localhost:8000我的服务

也许有一些其他方式来使用我的服务即我是否应该使用可以使用svcutil生成的代理 ?

也许有更好的方法。添加服务参考似乎不工作 ,我不知道为什么。

+0

你可以发布代码,你从客户服务调用服务器服务? – Alex 2013-03-01 10:27:39

+0

我没有代码,因为这是我想要实现的 – 2013-03-01 10:59:43

回答

1

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

+0

我已经在自承载exe中定义了它。大概这还不够,试试吧 – 2013-03-01 10:27:56

+0

好吧,让我知道它怎么样 – W1ck3dHcH 2013-03-01 10:38:54

+0

似乎没有工作。现在编辑我的问题 – 2013-03-01 10:47:35

0

至少有4种可能性:

  • 元数据交换MEX终结没有定义
  • 元数据交换不启用
  • 您使用了错误的地址
  • 你被封锁一些安全设置

There was an error downloading metadata from the address

+0

mex在selfhosting exe中定义,服务自己没有定义端点。已经发布了代码。我已经使用MEX为我的客户生成代理。它工作正常 – 2013-03-01 11:00:22

+0

正如我所看到的,在GeneralWorkService和GeneralDatabaseService中都有 。尝试更改“mex1”和“mex2”中的地址。我想当你启动你的服务时,你的两个mex点可能会有冲突,因为它们都有名称http:// localhost:8080/mex。 在IIS中,您的服务的完整路径由IIS本身生成,此示例可能在此处生效。但是,如果我没有错 - 自我托管的应用程序只是结合您的基地址和端点的地址,而不修改它们 – Alex 2013-03-01 11:21:47

+0

已经改变它,但这没有什么区别。 – 2013-03-01 11:34:41

0

终于找到了答案。

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

从这一点起,对话框中的错误信息(链接“详细信息”在底部) 是有帮助的。

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

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