簡體   English   中英

Contract需要Session,但是綁定'WSHttpBinding'不支持它。 帶有TransportWithMessageCredential的404

[英]Contract requires Session, but Binding 'WSHttpBinding' doesn't support it; 404 with TransportWithMessageCredential

我正在嘗試使WCF服務能夠通過HTTPS進行通信。

服務器配置:

<system.serviceModel>
  <services>
    <service name="PortalServiceLibrary.PortalService" behaviorConfiguration="PortalServiceBehavior">
      <endpoint address="" binding="wsHttpBinding" contract="PortalServiceLibrary.IPortalService">
        <identity>
          <dns value="vmserver"/>
        </identity>
      </endpoint>
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:8732/Design_Time_Addresses/PortalServiceLibrary/PortalService/"/>
        </baseAddresses>
      </host>
    </service>            
  </services>

  <behaviors>
    <serviceBehaviors>
      <behavior name="PortalServiceBehavior">
        <serviceMetadata httpsGetEnabled="True"/>
        <serviceDebug includeExceptionDetailInFaults="True"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>

  <bindings>
    <wsHttpBinding>
      <binding name="bindingAction" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647">
      </binding>
    </wsHttpBinding>
  </bindings>

  <protocolMapping>
    <add scheme="http" binding="wsHttpBinding"/>
    <add scheme="https" binding="wsHttpBinding"/>
  </protocolMapping>

</system.serviceModel>

客戶端配置:

<system.serviceModel>
  <bindings>
    <wsHttpBinding>
      <binding name="WSHttpBinding_IPortalService" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
        <readerQuotas maxDepth="32" maxStringContentLength="100000" maxArrayLength="2147483647"
          maxBytesPerRead="4096" maxNameTableCharCount="16384" />
        <security mode="TransportWithMessageCredential">
        </security>
      </binding>
    </wsHttpBinding>
  </bindings>
  <client>
    <endpoint address="https://vmserver/PortalService.svc"
        binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IPortalService"
        contract="PortalService.IPortalService" name="WSHttpBinding_IPortalService">
    </endpoint>
  </client>
</system.serviceModel>

當我使用時:

<security mode="Transport">

我收到以下錯誤:

Contract requires Session, but Binding 'WSHttpBinding' doesn't support it or isn't configured properly to support it. 

但是當我將其更改為:

<security mode="TransportWithMessageCredential">

我收到以下異常:

[WebException: The remote server returned an error: (404) Not Found.]
System.Net.HttpWebRequest.GetResponse() +6592536
System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +55

[EndpointNotFoundException: There was no endpoint listening at https://vmserver/PortalService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +10733331
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +336
Portal.PortalService.IPortalService.GetToken(TokenRequest request) +0
...

我真的不知道該朝哪個方向前進,因為我看上去很卡住。 任何幫助將不勝感激。

首先,

在客戶端配置中指定的<wsHttpBinding>綁定與在服務配置中指定的綁定不同。

請從客戶端配置中復制綁定,然后將其粘貼到服務配置中。

<wsHttpBinding>
  <binding name="WSHttpBinding_IPortalService" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
    <readerQuotas maxDepth="32" maxStringContentLength="100000" maxArrayLength="2147483647"
      maxBytesPerRead="4096" maxNameTableCharCount="16384" />
    <security mode="TransportWithMessageCredential">
    </security>
  </binding>
</wsHttpBinding>

也,

將服務端點(尚未在此處發布)更新為bindingConfiguration="WSHttpBinding_IPortalService"以及端點地址。

這應至少解決未找到的問題。

希望這可以幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM