Morcilla de Arroz
Morcilla de Arroz

Reputation: 2182

Xamarin + WCF + SSL + Transport + Certificate

I have a Net Framework 4.5 WCF Service, running with async/task methods. It is deployed on a valid URL, with a correct Digicert certificate, assuring the domain. We have a "client certificate", with a "one-to-one" mapping, and all its ok for our "Winforms" apps. Now, we wan't to call it from our Android/iOS Xamarin projects. We know that Xamarin doesn't supports wsBinding, so we're are using this config:

Server

<system.serviceModel>
    <services>
      <service
          name="serviceWCF.nameService"
          behaviorConfiguration="behavior_base">
        <endpoint address=""
                  binding="basicHttpBinding"
                  bindingConfiguration="transport"
                  contract="serviceWCF.nameInterfaceService" />
      </service>
    </services>
    <bindings>
    <basicHttpBinding>
        <binding name="transport">
          <security mode="Transport" >
            <transport clientCredentialType="Certificate"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="behavior_base">
          <serviceMetadata httpsGetEnabled="true" httpsGetUrl=""/>
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
  </system.serviceModel>

We created a proxy from SVCUTIL.EXE, then we have implement manually the async methods, channel creation, because Xamarin doesn't supports dinamic bindings, and so on.

The proxy for our Xamarin client app, it's invoked so:

BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
AddressHeader addressHeader2;
AddressHeader[] addressHeaders;
EndpointAddress endpoint;

addressHeader2 = AddressHeader.CreateAddressHeader("nameapp_iOS", "https:\\URL_WCF_Service.svc", 0);
addressHeaders = new AddressHeader[]{ addressHeader2};
endpoint = new EndpointAddress(new System.Uri("https:\\URL_WCF_Service.svc"),addressHeaders);

System.Security.Cryptography.X509Certificates.X509Certificate2 oCert;
oCert = new System.Security.Cryptography.X509Certificates.X509Certificate2(System.IO.File.ReadAllBytes("CertBundle.pfx"), "pass");

Service_MovilClient oProxy = new Service_MovilClient(binding, endpoint);
Service_MovilClient oProxy.ClientCredentials.ClientCertificate.Certificate = oCert 

But ... nothing happens... time out....

The server it's ok. The url can be accessed from the iOS emulator. We can use it with only "basicHttpBinding", but, we want to use SSL+Client Certificate.

Any ideas? Now I'm stuck.

Upvotes: 3

Views: 885

Answers (1)

Morcilla de Arroz
Morcilla de Arroz

Reputation: 2182

It's worthless to spoil more efforts. By now, WCF Xamarin its very short. I have to settle for with HTTPs and a basic Transport Security (security mode="Transport").

I have to use that Wcf services ... But if you, pathetic human, are reading this prior a new development, use REST services. They have a much better support form Xamarin.

Upvotes: 2

Related Questions