简体   繁体   中英

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

I am trying to enable my WCF service to communicate via HTTPS.

Server config:

<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>

Client Config:

<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>

When I use:

<security mode="Transport">

I receive the following error:

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

But when I change it to:

<security mode="TransportWithMessageCredential">

I receive the following exception:

[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
...

I'm really not sure what direction to go in here as I appear quite stuck. Any help will be greatly appreciated.

First of all,

The <wsHttpBinding> bindings specified in your Client config is different from what is specified in your service config.

Please copy the bindings from your client config and paste it in your service config.

<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>

Also,

Update your service endpoints (which you have not posted here) to bindingConfiguration="WSHttpBinding_IPortalService" and also the endpoint address.

This should atleast resolve the not found issue.

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM