2014-02-26 133 views
0

我遇到了我正在開發的客戶端 - 服務器應用程序的問題。使用遠程WCF服務

我已經爲客戶端部分創建了一個Windows窗體應用程序,併爲服務器部分創建了一個WCF應用程序。 我正在使用Visual Studio 2010.該應用程序在本地運行良好,但我需要將它們分開。我想在連接到與客戶端應用程序相同的LAN的遠程PC中運行服務器應用程序。

每次調試我的服務器應用程序,它運行在「HTTP:/ /本地主機:端口」,但我需要它在「HTTP:/ /192.168.1.xxx:port」運行。以便我可以使用該地址將服務導入到我的客戶端應用程序:「http:/ /192.168.1.xxx:port/Service1.svc」

我還有一個問題。如何導出我的服務器應用程序以隨時隨地運行它?即如何運行我的服務器應用程序,而無需在Visual Studio 2010上進行調試?

這些都是我的配置文件,我的服務:

客戶端(的app.config):

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
<system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
      <binding name="BasicHttpBinding_IValidacionesService" closeTimeout="00:01:00" 
       openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
       allowCookies="false" bypassProxyOnLocalhostNameComparisonMode="StrongWildcard" 
       maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" 
       messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
       useDefaultWebProxy="true"> 
       <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
        maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
       <security mode="None"> 
        <transport clientCredentialType="None" proxyCredentialType="None" 
         realm="" /> 
        <message clientCredentialType="UserName" algorithmSuite="Default" /> 
       </security> 
      </binding> 
      <binding name="BasicHttpBinding_IEncuestaCRUDService" closeTimeout="00:01:00" 
       openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
       allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
       maxBufferSize="6553600" maxBufferPoolSize="52428800" maxReceivedMessageSize="6553600" 
       messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
       useDefaultWebProxy="true"> 
       <readerQuotas maxDepth="3200" maxStringContentLength="819200" maxArrayLength="1638400" 
        maxBytesPerRead="409600" maxNameTableCharCount="1638400" /> 
       <security mode="None"> 
        <transport clientCredentialType="None" proxyCredentialType="None" 
         realm="" /> 
        <message clientCredentialType="UserName" algorithmSuite="Default" /> 
       </security> 
      </binding> 
     </basicHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http:/ /localhost:2504/ValidacionesService.svc" 
      binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IValidacionesService" 
      contract="ServiceValidacionesReference.IValidacionesService" 
      name="BasicHttpBinding_IValidacionesService" /> 
     <endpoint address="http:/ /localhost:2504/EncuestaCRUDService.svc" 
      binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IEncuestaCRUDService" 
      contract="ServiceEncuestaReference.IEncuestaCRUDService" name="BasicHttpBinding_IEncuestaCRUDService" /> 
    </client> 
</system.serviceModel> 

服務器端(web.config中):

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0"> 
     <assemblies> 
     <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
     </assemblies> 
    </compilation> 
    </system.web> 
    <system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> 
      <serviceMetadata httpGetEnabled="true" /> 
      <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true" /> 
    </system.webServer> 
    <connectionStrings> 
<add name="CADBEntities" connectionString="metadata=res://*/ModeloCaDB.csdl|res://*/ModeloCaDB.ssdl|res://*/ModeloCaDB.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=OMSUser\SQLEXPRESS;initial catalog=CADB;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> 

在此先感謝。

回答

0

你的客戶端正試圖與EndpointAddress通信設置爲本地主機這意味着當前的計算機。

它必須配置爲聯繫承載WCF服務的機器的IP地址。

下面是如何在客戶端配置文件中執行此操作的示例。

<system.serviceModel> 
    <client> 
     <endpoint address="http://192.168.1.xxx:port/Service1.svc" 
      binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IValidacionesService" 
      contract="IValidacionesService" name="BasicHttpBinding_IValidacionesService"> 
     </endpoint> 
    </client> 
</system.serviceModel> 
+0

我已經這樣做了,但我無法連接到服務器。 – omaestra

+0

你現在自己託管這項服務嗎?我看到你還沒有致力於IIS。 –

+0

是的,我自己託管服務。爲什麼我應該將它提交給IIS? – omaestra

1

您需要將WCF服務託管爲另一臺計算機上的IIS站點。

VS有幾種方法可以將需要的文件發佈到其他機器上,儘管最簡單的方法可能是通過網絡共享。

這是link發佈WCF服務的基礎知識。

+2

WCF沒有*可以通過IIS託管。 –

+0

你是對的,但似乎是OP想要做的。 – dbugger

+0

我不認爲OP知道他想做什麼,但是使用基於HTTP的綁定仍然不能真正表明IIS是他所追求的。 –

相關問題