合同需要Session,但Binding'WSHttpBinding'不支持它; 404与TransportWithMessageCredential

时间:2014-09-09 20:16:57

标签: wcf https

我正在尝试启用我的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
...

我真的不确定这里的方向,因为我看起来很困难。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

首先,

客户端配置中指定的<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"以及端点地址。

这至少可以解决未发现的问题。

希望这有帮助