请帮助一个菜鸟了解服务参考绑定

时间:2012-02-15 21:45:15

标签: asp.net soap

我最近被要求连接到第三方Web服务(* .asmx)。我创建了一个新的ASP.NET网站,并使用该向导创建了服务引用。当我去调用该服务时,代码抱怨说它不知道要使用哪个端点。

我查看了Web.config,果然,向导创建了两个绑定,因此创建了两个端点。通过在服务调用中添加任一端点,一切都运行良好。

我的问题仅仅是为了帮助我理解为什么我有两个绑定,如果有某些原因我应该使用一个而不是另一个?或者我应该删除一个,如果是,那么?

绑定看起来与我完全不同,我假设正在使用两种不同的协议(但它们都标记为SOAP,所以......)。我非常“专注于前端”并且不经常参与后端机制,这就是我要问的原因。我将在下面发布绑定。

    <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="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>
      <httpTransport 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" />
    </binding>
  </customBinding>
</bindings>
<client>
  <endpoint address="http://someURL.asmx" binding="basicHttpBinding"
    bindingConfiguration="ServiceSoap" contract="ServiceReference.ServiceSoap"
    name="ServiceSoap" />
  <endpoint address="http://someURL.asmx" binding="customBinding"
    bindingConfiguration="ServiceSoap12" contract="ServiceReference.ServiceSoap"
    name="ServiceSoap12" />
</client>

2 个答案:

答案 0 :(得分:1)

看起来这个服务只是暴露了两个具有不同编码的端点。

如果它同时允许http和https,你也会看到两个绑定。

答案 1 :(得分:1)

我相信该服务提供了SOAP 1.1和SOAP 1.2。您需要指定要在服务引用类的构造函数中使用的客户端配置:

var client = new MyClient("ServiceSoap12");