C# 使用远程WCF服务

C# 使用远程WCF服务,c#,visual-studio-2010,wcf,C#,Visual Studio 2010,Wcf,我正在开发的客户机-服务器应用程序出现问题 我已经为客户端部分创建了一个Windows窗体应用程序,为服务器部分创建了一个WCF应用程序。 我正在使用VisualStudio2010。该应用程序在本地运行良好,但我需要将它们分开。我想在与客户端应用程序连接到同一LAN的远程PC上运行服务器应用程序 每次调试我的服务器应用程序时,它都在“http://localhost:port”上运行,但我需要它在“http://192.168.1.xxx:port”上运行。因此,我可以使用以下地址将服务导入到

我正在开发的客户机-服务器应用程序出现问题

我已经为客户端部分创建了一个Windows窗体应用程序,为服务器部分创建了一个WCF应用程序。 我正在使用VisualStudio2010。该应用程序在本地运行良好,但我需要将它们分开。我想在与客户端应用程序连接到同一LAN的远程PC上运行服务器应用程序

每次调试我的服务器应用程序时,它都在“http://localhost:port”上运行,但我需要它在“http://192.168.1.xxx:port”上运行。因此,我可以使用以下地址将服务导入到我的客户端应用程序:“http://192.168.1.xxx:port/Service1.svc”

我还有一个问题。如何导出服务器应用程序以在任何地方运行它?i、 e.如何在不调试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>
<?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" />

服务器端(web.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>
<?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" />


提前感谢。

您的客户端正在尝试与设置为本地主机的主机进行通信,该主机表示当前计算机

必须将其配置为联系承载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>

您需要将WCF服务作为IIS站点托管在另一台计算机上

VS有几种方法可以将所需的文件发布到另一台机器上,不过最简单的方法可能是通过网络共享


以下是发布WCF服务的基本方法。

WCF不必通过IIS托管。你是对的,但这似乎是OP想要做的。我不认为OP知道他想要做什么,但使用基于HTTP的绑定仍然不能真正表明他想要的是IIS。这两方面都是真的,但这可能是学习过程中最简单的方法。没错,我不知道我想做什么。我只需要在另一台电脑上运行我的服务器应用程序,并使用我的服务器IP添加我的服务引用。你现在是否自行托管此服务?我看到你还没有加入IIS。是的,我正在自托管服务。为什么我要将其提交给IIS?不,您肯定不需要使用IIS(实际上,我更喜欢自托管)。我只是好奇你的服务器端是如何设置的。那么呢?如何将客户端连接到远程服务器?第二,如何在VS2010上从我的服务器应用程序中释放我的.exe文件?