none
Conversion from WSE2.0 to WCF (framework 4.5) RRS feed

  • Question

  • HI, I have a web service in which WSE2.0 is used with below methods. Now, i want to convert it into WCF as WSE2.0 is obsolete. Can you please tell me the best way /step to convert it into WCF? 

    #region get certificate
    private X509SecurityToken GetSecurityToken(string which, bool IsTokenForSigning, string certname)
    {
    X509SecurityToken securityToken = null;
    X509CertificateStore store = null;
    bool getPrivate = which == "private";
    try
    {
    store = X509CertificateStore.LocalMachineStore(getPrivate ? X509CertificateStore.MyStore : X509CertificateStore.OtherPeople);
    store.OpenRead();
    //X509CertificateCollection certs  = store.FindCertificateBySubjectString(getPrivate ? "APC08GJB8" : "shi006labt04.shdc.chrysler.com"); 
    X509CertificateCollection certs = store.FindCertificateBySubjectString(certname);
    if (certs.Count > 0)
    {
    X509Certificate cert = (X509Certificate)certs[0];
    if (cert == null)
    {
    throw new ApplicationException("Could not find the X.509 certificate.");

    }
    else if (IsTokenForSigning && (!cert.SupportsDigitalSignature || (cert.Key == null)))
    {
    throw new ApplicationException("The certificate must support digital signatures and have a private key available.");
    }
    else if (!cert.SupportsDataEncryption)
    {
    throw new ApplicationException("The certificate must support data  encryption.");
    }
    else
    {
    securityToken = new X509SecurityToken(cert);
    }
    }
    else
    {
    throw new ApplicationException("Could not find the X.509 certificate.");
    }
    }
    catch 
    {
    securityToken = null;
    }
    finally
    {
    if (store != null)
    store.Close();
    }
    return securityToken;
    }
    #endregion

    #region setup security
    private void SetupWSE(Microsoft.Web.Services2.WebServicesClientProtocol wse, string url, string cert, string security, string user, string pwd,int timeout)
    {
    wse.Url = url;
    wse.Timeout = timeout;
    if (security == "S")
    {
    //X509SecurityToken encryptionToken = GetSecurityToken("public", false, cert);
    X509SecurityToken encryptionToken = GetSecurityToken("private", false, cert);
    wse.RequestSoapContext.Security.Elements.Add(new EncryptedData(encryptionToken));
    UsernameToken TextToken = new UsernameToken(user, pwd, PasswordOption.SendPlainText);
    wse.RequestSoapContext.Security.Tokens.Add(TextToken);
    }
    else
    {
    NetworkCredential netCredential = new NetworkCredential(user, pwd);
    ICredentials credentials = netCredential.GetCredential(new Uri(url), "Basic");
    wse.Credentials = credentials;
    wse.PreAuthenticate = true;
    }
    }
    #endregion


    Tuesday, April 5, 2016 7:01 AM

Answers

  • Hello,

    Based on your WSE code, in my mind you may need to configure the WCF Service to use the username authentication to implement the similar function. In WCF Service if you want to implement a username authentication, a service certificate is required. For more information, please try to refer to:
    How to: Use a Custom User Name Authentication in WCF.

    After that the client need to provide the correct credentials as following:

    client.ClientCredentials.UserName.UserName = "username"
    client.ClientCredentials.UserName.Password = "password"

    Since WCF have a big change from the WSE, I will suggest you leave your WSE code alone and create a new project for WCF to implement the similar feature. You may end up running both sets of web services for a while until the clients can also migrate.

    Besides, please also refer to the following article about how to convert the WSE to WCF service:
    https://msdn.microsoft.com/en-us/library/ms732008(v=vs.110).aspx .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, April 7, 2016 10:26 AM
    Moderator