为一个与多个Web服务(一些通过dll)对话的站点配置web.config(system.serviceModel)

时间:2011-02-08 03:13:00

标签: asp.net wcf configuration web-config wcf-configuration

我有一个由Web项目和类库项目组成的解决方案。 Web项目解决方案直接引用wcf服务。有第二个wcf服务,但它是直接引用它的类库项目。我正在添加类库(输出)作为我的web项目的参考。

因此,在我的web项目的web.config中,我现在配置了两个scf服务。这个过程很简单,因为我手动将app.config(system.serviceModel部分)直接复制到web.config,然后配置了web项目直接与另一个wcf服务对话(直接,不是通过任何dll)。

我的网络项目需要与第三个网络服务(asmx)交谈。我再次计划将其作为类库并将dll包含到我的Web项目中。 (这是一个单独的解决方案)。当我看一下这个特定的类lib项目的app.config时,我想我只是复制那些必要的部分并将它与我当前的web.config相对应地合并。

因此,对于第三类lib项目(引用asmx服务),我碰巧注意到它在绑定节点下有一个名为basicHttpBinding的节点,接下来是一个customBinding。然后在客户端节点下面,有两个具有服务属性的端点节点。 (我不明白为什么首先应该有两个终点。)

所以我复制了绑定节点下的内容(来自第3类lib prj app.config)并将其附加到绑定节点(在web.config中)。我也做了类似的复制端点的过程。但是现在当我尝试运行网站时,我得到一个异常,它在初始化soap客户端(asmx服务)时停止:它说它无法确定此合同的端点。

添加asmx Web服务之前的web.config如下所示:

  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="WSHttpBinding_IEmployeeService" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
          maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
          textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00"
            enabled="false" />
          <security mode="Message">
            <transport clientCredentialType="Windows" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="Windows" negotiateServiceCredential="true"
              algorithmSuite="Default" />
          </security>
        </binding>
        <binding name="WSHttpBinding_IHelper" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
          maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
          textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00"
            enabled="false" />
          <security mode="Message">
            <transport clientCredentialType="Windows" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="Windows" negotiateServiceCredential="true"
              algorithmSuite="Default" />
          </security>
        </binding>
      </wsHttpBinding>      
    </bindings>
    <client>
      <endpoint address="http://localhost:8731/Design_Time_Addresses/InfiniumIS/EmployeeService/"
        binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IEmployeeService"
        contract="InfiniumWS.IEmployeeService" name="WSHttpBinding_IEmployeeService">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
      <endpoint address="http://localhost:8732/Design_Time_Addresses/SQLIS/Service1/"
        binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IHelper"
        contract="SQLIS.IHelper" name="WSHttpBinding_IHelper">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>

以下是使用asmx服务的项目服务模型(取自app.config)

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="ServiceSoap" 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="Transport">
                    <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
            </binding>
            <binding name="ServiceSoap1" 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>
        <customBinding>
            <binding name="ServiceSoap12">
                <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
                    messageVersion="Soap12" writeEncoding="utf-8">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                </textMessageEncoding>
                <httpsTransport manualAddressing="false" maxBufferPoolSize="524288"
                    maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
                    bypassProxyOnLocal="false" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard"
                    keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
                    realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
                    useDefaultWebProxy="true" requireClientCertificate="false" />
            </binding>
        </customBinding>
    </bindings>
    <client>
        <endpoint address="https://is.security/WebAppSec_WS/service.asmx"
            binding="basicHttpBinding" bindingConfiguration="ServiceSoap"
            contract="apps.intranet.ws.ServiceSoap" name="ServiceSoap" />
        <endpoint address="https://is.security/WebAppSec_WS/service.asmx"
            binding="customBinding" bindingConfiguration="ServiceSoap12"
            contract="apps.intranet.ws.ServiceSoap" name="ServiceSoap12" />
    </client>
</system.serviceModel>

我简单地合并了这些部分 - 意味着复制了绑定节点下第二个配置中的任何内容,并将其添加到第一个配置节点。我做了类似的复制端点的过程。

ps:我不知道为什么第二个配置(asmx)会向我显示两个端点?

1 个答案:

答案 0 :(得分:0)

ASMX结尾使用两种不同的绑定。第一个绑定是HTTP,而第二个绑定是HTTPS。假设ASMX服务同时支持HTTP和HTTPS,您应该能够从客户端配置中删除其中一个端点。