Wcf access via https

Asked

Viewed 114 times

0

I have the following error accessing a https url:

O esquema de URI do provedor 'https' é inválido; esperado 'http'.\r\nNome do parâmetro: via

My file to

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <client>
      <endpoint address="https://teste.com.br/Service1.svc" binding="wsHttpBinding" 
    bindingConfiguration="ServiceBinding1" contract="ServiceReference.ServiceContract"
    name="ServiceBinding" />
    </client>
    <bindings>
      <wsHttpBinding>
       <binding name="ServiceBinding1" maxReceivedMessageSize="2147483647">
         <reliableSession enabled="true" />
         <security mode="None" />    
       </binding>
      </wsHttpBinding>
    </bindings>
  </system.serviceModel>
  <startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
</configuration>

I tried it this way too:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <system.serviceModel>
  <behaviors>
   <serviceBehaviors>
    <behavior name="MyServiceBehavior">
      <serviceMetadata httpsGetEnabled="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<client>
   <endpoint address="https://teste.com.br/AgroMobileWCF/Service1.svc" binding="wsHttpBinding" 
    bindingConfiguration="ServiceBinding1" contract="ServiceReference.ServiceContract"
    name="ServiceBinding1" />
</client>
<bindings>
  <wsHttpBinding>
    <binding name="ServiceBinding1" maxReceivedMessageSize="2147483647">
      <reliableSession enabled="true" />
      <security mode="Transport">
        <transport clientCredentialType="None"/>
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>

I got the following error:

Falha na validação de associação porque o WSHttpBinding não oferece suporte a sessões confiáveis em segurança de transporte (HTTPS). A fábrica de canais ou host de serviço não pôde ser aberto. Use a segurança de mensagem para proteger a troca de mensagens confiáveis em HTTP.

Requisition code:

    public void Connect()
    {
        try
        {
            if (client != null)
                client.Disconnect();
        }
        catch { }
        try
        {
            ServiceReference.ServiceContractClient.CacheSetting = CacheSetting.AlwaysOn;
            client = new ServiceReference.ServiceContractClient();
            TimeSpan ts = new TimeSpan(0, 0, 0, 11);
            client.Endpoint.Binding.CloseTimeout = ts;
            client.Endpoint.Binding.OpenTimeout = ts;
            client.Endpoint.Binding.ReceiveTimeout = ts;
            client.Endpoint.Binding.SendTimeout = ts;

            client.Connect();

            var loginResult = (ServiceReference.LoginResult)client.SendLogin("CT", 1);

            if (!"OK".Equals(loginResult.STATUS))
                throw new Exception("Erro: " + loginResult.MENSAGEM);
        }
        catch (Exception ex) { return; }// throw ex; }
    }



[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class ServiceContractClient : System.ServiceModel.ClientBase<LarWS.ServiceReference.ServiceContract>, LarWS.ServiceReference.ServiceContract {

 public LarWS.ServiceReference.Message Connect() {
        return base.Channel.Connect();
    }
 }

1 answer

0

Modify your HttpBinding to configure security mode for Transport

<bindings>
  <wsHttpBinding>
   <binding name="ServiceBinding1" maxReceivedMessageSize="2147483647">
     <reliableSession enabled="true" />         
     <security mode="Transport">
         <transport clientCredentialType="None"/>
     </security>   
   </binding>
  </wsHttpBinding>
</bindings>

And enable https in behaviour

<system.serviceModel>
    <behaviors>
        <serviceBehaviors>                
            <behavior name="MyServiceBehavior">
                <serviceMetadata httpsGetEnabled="true"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <!-- ... -->
</system.serviceModel>
  • Leandro, I tried to do the way you did, I got an error, as I asked the question. att

  • Actually your first problem was "solved", now you have to change your code and authenticate to consume the service. Include in your question the code of your request.

  • Leandro, include the code where I make the request.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.