C# 尝试在wcf服务运行的外部访问wcf服务时无法访问该服务

C# 尝试在wcf服务运行的外部访问wcf服务时无法访问该服务,c#,wcf,C#,Wcf,我的简单wcf运行正常,因为当我尝试为wcf创建应用程序时,它会返回预期的数据,但当我尝试在wcf服务运行之外运行应用程序时,它会给出错误消息 如何解决此问题 wcf服务web配置 <?xml version="1.0"?> <configuration> <system.web> <compilation debug="true" targetFramework="4.0" /&g

我的简单wcf运行正常,因为当我尝试为wcf创建应用程序时,它会返回预期的数据,但当我尝试在wcf服务运行之外运行应用程序时,它会给出错误消息

如何解决此问题

wcf服务web配置

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

          <system.web>
            <compilation debug="true" targetFramework="4.0" />
          </system.web>
          <system.serviceModel>
<services>
      <service name="WcfService1.Service1">
        <endpoint address="http://192.168.21.102:4424/Service1.svc"
                  binding="wsHttpBinding"
                  contract="WcfService1.IService1"></endpoint>
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange"></endpoint>
      </service>
    </services>
            <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="false"/>
                </behavior>
              </serviceBehaviors>
            </behaviors> 
            <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
          </system.serviceModel>
         <system.webServer>
            <modules runAllManagedModulesForAllRequests="true"/>
          </system.webServer>

        </configuration>

客户端应用程序配置

    <?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IService1" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="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>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:4424/Service1.svc" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
                name="BasicHttpBinding_IService1" />
        </client>
    </system.serviceModel>
</configuration>

我没有触摸或编辑这些东西

两件事:

首先,您的服务被定义为使用
wsHttpBinding
,但您的客户机使用的是
basicHttpBinding
。绑定需要匹配

其次,客户端配置中的地址设置为
localhost
——这意味着您的客户端正在客户端所在的同一台机器上查找服务

例如,如果您的服务在一台名为MySever1的机器上(例如),并且您将客户机(带有发布的配置)放在一台名为MyClient1的机器上(同样,例如),它将在MyClient1(客户机的本地主机)上查找服务

将客户端端点更改为
http://192.168.21.102:4424/Service1.svc
并且您应该能够连接,除非出现任何防火墙问题

例如:

<client>
  <endpoint address="http://192.168.21.102:4424/Service1.svc" 
            binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_IService1" 
            contract="ServiceReference1.IService1"
            name="BasicHttpBinding_IService1" />
</client>

编辑

在服务端配置中,对端点执行以下操作:

service name="WcfService1.Service1">
    <endpoint address=""
              binding="basicHttpBinding"
              contract="WcfService1.IService1">
    </endpoint>
    <endpoint address="mex"
              binding="mexHttpBinding"
              contract="IMetadataExchange">
    </endpoint>
  </service>
service name=“WcfService1.Service1”>
在客户端配置中:

<client>
  <endpoint address="http://192.168.21.102:4424/Service1.svc"
            binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_IService1" 
            contract="ServiceReference1.IService1"
            name="BasicHttpBinding_IService1" />
</client>

请注意,在服务端点声明中,
address
属性为空-可以使用*.svc文件的位置来确定实际地址。其次,将绑定更改为
basicHttpBinding
,以匹配客户端将调用的内容


在客户端配置中,指定您正在调用的服务的完整地址。

您的应用程序是否有带有WCF配置的app.config?@Hyralex,我没有,只有一个webconfig@SHINHAN-您能否澄清WCF之外的
应用程序是什么意思?您是否正在尝试在不托管服务的情况下运行该服务?或者试图通过客户端从另一台计算机连接到它?@Tim通过客户端从另一台计算机连接到它,@SHINHAN-这可能是任何事情之一。请发布您的服务配置和客户端配置,以及您尝试将客户端连接到服务时使用的代码。但当我尝试重建wcf解决方案并在浏览器中查看时,会出现错误“在配置中将'system.serviceModel/serviceHostingEnvironment/multipleSiteBindingsEnabled'设置为true时,端点需要指定相对地址。如果在端点上指定相对侦听URI,则地址可以是绝对地址。若要解决此问题,请为终结点“”指定一个相对uri。我已经尝试过了,但客户端给出了错误“没有侦听可以接受消息的终结点。这通常是由不正确的地址或SOAP操作引起的。有关更多详细信息,请参阅InnerException(如果存在)”@SHINHAN-内部异常说明了什么?InnerException={“无法建立连接,因为目标计算机主动拒绝了它192.168.21.102:4424”}当我尝试将站点导航到浏览器时,仍然无法访问它,但当将其更改为本地主机时,它是正常的