简体   繁体   中英

Send encrypted data wcf - windows phone

I'm using WCF service to communicate with DB. My WP7.5 application sends data through WCF to DB. I use basichttpbinding, because WP supports only this one. I would like to send data in encrypted form. I know, that https is used for these purposes. Here is my web.config:

<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="serviceBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<bindings>
  <basicHttpBinding>
      <binding name="baseBinding" >
      </binding>
  </basicHttpBinding>
</bindings>
<services>
  <service behaviorConfiguration="serviceBehavior" name="TestWCF.WcfNotificationService.WcfNotificationService">
    <endpoint address="base" binding="basicHttpBinding" bindingConfiguration="baseBinding"
      contract="TestWCF.WcfNotificationService.IWcfNotificationService" />
    <host>
      <timeouts openTimeout="00:05:00" />
    </host>
  </service>
</services>

I've googled and found that I have to set securityMode to transport, but it gives me an exception, when I try to update service reference in my WP application. Could you help me please, how to achieve this, that data will be encrypted? Thanks a lot!

EDIT

This is the error:

Could not find a base address that matches scheme for https for the endpoint with binding BasicHttpBinding. Registered base address schemes are [http].

I get this, when I update service reference in client.

It looks like you have a problem with the configuration. BasicHttpBinding needs to be configured to support https. For example look here : http://blog.adnanmasood.com/2008/07/16/https-with-basichttpbinding-note-to-self/

As pointed out there, you need to change:

<basicHttpBinding>
      <binding name="baseBinding" >
      </binding>
 </basicHttpBinding>

to

<basicHttpBinding>
      <binding name="baseBinding" >
          <security mode="Transport">
              <transport clientCredentialType="None"/>
           </security>
      </binding>
 </basicHttpBinding>

In addition, change

<serviceMetadata httpGetEnabled="true"/>

to

<serviceMetadata httpsGetEnabled="true"/>

If you are hosting your WCF service in IIS make sure you have https binding configured with an SSL certificate. Check out this to see how to configure this. If you are self hosting the service make sure you add a base address like this:

        <host>
          <baseAddresses>
            <add baseAddress="https://[machineName]/Service.svc"/>
          </baseAddresses>
        </host>

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