Asp.net-Mvc

更新服務參考堅持將 Soap12 添加到 Config。

  • January 17, 2012

當我更新服務參考時,我最終得到:

無法載入契約“MyService.MainServiceSoap”的端點配置部分,因為找到該契約的多個端點配置。請按名稱指明首選端點配置部分。

我的 web.config 最終是這樣的:

端點:

 <endpoint address="http://localhost/main/MainService.asmx"
   binding="basicHttpBinding" bindingConfiguration="MainServiceSoap"
   contract="MyService.MainServiceSoap" name="MainServiceSoap" />
 <endpoint address="http://localhost/main/MainService.asmx"
   binding="customBinding" bindingConfiguration="MainServiceSoap12"
   contract="MyService.MainServiceSoap" name="MainServiceSoap12" />

綁定:

 <basicHttpBinding>
   <binding name="MainServiceSoap" closeTimeout="00:01:00" openTimeout="00:01:00"
     receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
     bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
     maxBufferSize="655360" maxBufferPoolSize="5242880" maxReceivedMessageSize="655360"
     messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
     useDefaultWebProxy="true">
     <readerQuotas maxDepth="32" maxStringContentLength="81920" maxArrayLength="163840"
       maxBytesPerRead="40960" maxNameTableCharCount="163840" />
     <security mode="None">
       <transport clientCredentialType="None" proxyCredentialType="None"
         realm="" />
       <message clientCredentialType="UserName" algorithmSuite="Default" />
     </security>
   </binding>
 </basicHttpBinding>
 <customBinding>
   <binding name="MainServiceSoap12">
     <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>

我手動刪除了 customBinding 和 Soap12 端點,一切正常。但是,如果我再次更新服務(右鍵點擊更新服務參考),添加的自定義綁定會再次添加,從而導致錯誤並且需要從配置文件中手動刪除。

有人知道如何解決這個問題嗎?我不想要/不需要自定義soap12 綁定。

這是服務配置文件:

<?xml version="1.0"?>
<configuration>
 <system.web>
   <globalization culture="es-PY" uiCulture="es-PY"/>
   <customErrors mode="Off"/>
   <webServices>
<!-- Tried adding and/or removing protocols and conformanceWarnings -->
     <protocols>
       <add name="HttpGet"/>
       <add name="HttpPost"/>
     </protocols>
<!-- -->
     <conformanceWarnings>
       <remove name="BasicProfile1_1"/>
     </conformanceWarnings>
   </webServices>
   <compilation debug="true" targetFramework="4.0"/>
 </system.web>
 <system.serviceModel>
   <standardEndpoints>
     <webHttpEndpoint>
       <standardEndpoint name="standard" maxReceivedMessageSize="6553600" maxBufferSize="6553600" transferMode="Streamed" helpEnabled="true" automaticFormatSelectionEnabled="true">
         <readerQuotas maxStringContentLength="65536000" maxArrayLength="163840" />
       </standardEndpoint>
     </webHttpEndpoint>
   </standardEndpoints>
   <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>
<!-- Tried setting multipleSiteBindingEnalbed true and false -->
   <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"/>
<!--  -->

 </system.serviceModel>
 <system.webServer>
   <modules runAllManagedModulesForAllRequests="true"/>
 </system.webServer>
 <connectionStrings>
   <clear/>
   <add name="GamblingEntities" connectionString="..." providerName="System.Data.EntityClient" />
   <add name="GamblingSiteEntities" connectionString="..." providerName="System.Data.EntityClient" />
 </connectionStrings>
 <system.data>
   <DbProviderFactories>
     <clear/>
     <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, 
Version=6.3.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
   </DbProviderFactories>
 </system.data>
</configuration>

.NET 2.0 中的新 ASMX 執行時支持 SOAP 1.2。目前 SOAP 1.1 是業界使用最廣泛的。在 .NET Framework 中,SOAP 1.1 和 SOAP 1.2 都受支持。這意味著在 .NET Framework 2.0 中創建的 Web 服務將被配置為支持 SOAP 1.1 和 SOAP 1.2 消息。這間接意味著為 Web 服務創建的 WSDL 將具有兩種類型的綁定,即 SOAP 1.1 和 SOAP 1.2。

取自這裡

這就是生成兩個綁定的原因。

<remove name="HttpSoap12"/>

我想這就是你現在如何禁用它的原因,我可以理解為什麼你認為這是一種解決方法。當您將 Web 服務移至新框架時,可能會出現這種情況,這就是為什麼 1.1 上的一些舊 Web 服務可能不會以相同的方式響應。嘗試以 2.0 框架為目標,看看會發生什麼。

引用自:https://stackoverflow.com/questions/8679641