2013-03-01 80 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的回答,因爲它是正確的,但我只是沒有看到它。