# .NET and More > WPF, WCF, WF >  [RESOLVED] Going back to WCF, using SSL

## sapator

Hey,


```
  <security mode ="TransportWithMessageCredential">
          <message clientCredentialType="UserName" />
```

I am trying to work out an ssl - certificate site. This time the company has some real bought certificates so i am good to go this field.
What i want to ask is about the above code. I am thinking of implementing  TransportWithMessageCredential with  clientCredentialType="UserName"  so already set security and no custom user-pass security level. I have seen tons of samples and to my surprise, not many will mention how the client will set the username pass security up. After downloading a MS sample and searching through hundreds of directories (actually i search for TransportWithMessageCredential with a tool) i found a "working sample" it used system.servicemodel.description.clientcredentials to pass fake creds (i will fix that) and it continues normally.
2 things here
1)I've read that client creds only needed as "fakes" for the aforementioned WCF service. Regardless on if i will use the creds correctly afterwards, is this the "basic" behavior?
2)I get to a point that:


```

  client.ClientCredentials.UserName.UserName = username
            client.ClientCredentials.UserName.Password = password.ToString()

            ' Call the GetCallerIdentity service operation
            Console.WriteLine(client.GetCallerIdentity())
```

GetCallerIdentity will produce the following issue:
"An error occurred while making the HTTP request to https://localhost/servicemodelsamples/service.svc. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server."

Is this an issue with the "fake" cert MS sample use or something else?
and


```
 Public Function GetCallerIdentity() As String Implements ICalculator.GetCallerIdentity

            ' use ServiceSecurityContext.WindowsIdentity to get the name of the caller
            Return ServiceSecurityContext.Current.WindowsIdentity.Name

        End Function
```

Thanks.

----------


## sapator

P.S just migrated to VS2010 and nothing works! System servicemodel is not there?
Got to look at this again.

----------


## sapator

Ok took care of the vs2010 issue (you don't wanna know @#$#$@#$@#$ Microsoft).
So back to this ""An error occurred while making the HTTP request to https://localhost/servicemodelsamples/service.svc. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server.""

----------


## sapator

Ok, i kinda fixed that i guess or it will come back. Anyhow now i have created 2 solutions. One wcf library and one wcf application. The library seems to work fine, meaning will open the wcf (then calling it will fail saying it needs http balh balh, anyhow ignore).
WCF application with the EXACT SAME web.config will fail saying
""Error: Cannot obtain Metadata from http://localhost:55745/VSAPI.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address.  For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?Link...55.WS-Metadata Exchange Error    URI: http://localhost:55745/VSAPI.svc    Metadata contains a reference that cannot be resolved: 'http://localhost:55745/VSAPI.svc'.    Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost:55745/VSAPI.svc.  The client and service bindings may be mismatched.    The remote server returned an error: (415) Unsupported Media Type.HTTP GET Error    URI: http://localhost:55745/VSAPI.svc    The HTML document does not contain Web service discovery information."

WHY?! IT's the EXACT SAME!
here is the config file and thanks if anyone takes a look. From my previous experience with WCF i found a solution myself in about a month (ajax wcf , another solution) so i do not expect anyone to fix this but i am posting it anyhow.


```
<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service name="VSAPIService.VSAPI"  behaviorConfiguration="VSAPIServiceBehavior">
        <endpoint address="" binding="wsHttpBinding" contract="VSAPIService.IVSAPI">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8731/Design_Time_Addresses/VSAPIService/Service1/" />
          </baseAddresses>
        </host>
      </service>
    </services>

    <bindings>
      <wsHttpBinding>
        <!-- 
        This configuration defines the security mode as TransportWithMessageCredential 
        and the clientCredentialType as UserName.
        -->
        <binding name="Binding1">
          <security mode ="TransportWithMessageCredential">
            <message clientCredentialType="UserName" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>

    <behaviors>
      <serviceBehaviors>
        <behavior name="VSAPIServiceBehavior">
          <!-- 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="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

</configuration>
```

----------


## sapator

the issue is here:


```
<configuration>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="VSAPIBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    
    <services>
      <service behaviorConfiguration="VSAPIBehavior" name="VSAPI">
        <endpoint address="" binding="wsHttpBinding" contract="IVSAPI">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
  </system.serviceModel>
  <system.web>
    <compilation debug="true"/>
  </system.web>
</configuration>
```

if i remove the "name" from <behavior name="VSAPIBehavior"> and behaviorconfiguration from behaviorConfiguration="VSAPIBehavior"

it will work but of course this is not what i want because then it will not bind the behaviors.

----------


## sapator

This has , as i am testing now, been resolved.
There was an issue with the certificate so i requested a valid one from the company and it seems to work now.

----------

