0

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

在此处输入图像描述

我该如何解决这个问题?

wcf 服务网络配置

    <?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>

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

4

1 回答 1

1

两件事情:

首先,您的服务被定义为使用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>

在您的客户端配置中:

<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匹配客户端将调用的内容。

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

于 2013-05-02T04:44:41.237 回答