title: Consume Java weblogic web service having usernametoken and client certificate in ASP.Net
body: <p>i need to consume a web service developed with java web logic server, usernametoken and client certificate are used to invoke the service.
  and i got the java code to call web service as below</p>
  
  <pre><code>import javax.ejb.CreateException;
  import javax.ejb.SessionBean;
  import javax.ejb.SessionContext;
  import javax.naming.Context;
  import javax.naming.InitialContext;
  import javax.naming.NamingException;
  import java.rmi.RemoteException;
  import weblogic.wtc.jatmi.TPException;
  import weblogic.wtc.jatmi.TypedString;
  import weblogic.wtc.jatmi.Reply;
  import weblogic.wtc.jatmi.TuxedoReply;
  import weblogic.wtc.jatmi.TPServiceInformation;
  import weblogic.wtc.jatmi.TypedFML32;
  import weblogic.wtc.jatmi.TuxedoService;
  import weblogic.wtc.jatmi.TypedBuffer;
  import java.util.StringTokenizer;
  import java.io.IOException;
  import javax.xml.rpc.ServiceException;
  import MMSWbSrv.*;
  import java.util.Properties;
  import java.text.SimpleDateFormat;
  import java.io.BufferedReader;
  import java.io.InputStreamReader;
  import java.io.FileInputStream;
  import java.security.cert.X509Certificate;
  import weblogic.security.SSL.TrustManager;
  import weblogic.xml.crypto.wss.provider.CredentialProvider;
  import weblogic.xml.crypto.wss.WSSecurityContext;
  import weblogic.wsee.security.bst.ClientBSTCredentialProvider;
  import weblogic.wsee.security.unt.ClientUNTCredentialProvider;
  import java.security.cert.X509Certificate;
  import weblogic.wsee.security.util.CertUtils;
  import javax.xml.rpc.Stub;
  import java.util.List;
  import java.util.ArrayList;
  import java.util.regex.*;
  import weblogic.wtc.jatmi.TypedFML32;
  public class MMSTest
  {
  public static void main(String args[])  throws Throwable
  {
  
          Properties sysProps = System.getProperties();
          sysProps.setProperty("http.proxyHost","XXX.XX.X.XX");
          sysProps.setProperty("http.proxyPort","XXXX");
          sysProps.setProperty("weblogic.webservice.transport.http.proxy.host", "XXX.XX.X.XX");
          sysProps.setProperty("weblogic.webservice.transport.http.proxy.port", "XXXX");
          sysProps.setProperty("http.proxySet","true");
          sysProps.setProperty("weblogic.webservice.verbose","true");
  
          sysProps.setProperty("javax.net.ssl.trustStore","D:/weblogic92/server/lib/DemoTrust.jks");
  
          System.out.println("proxyHost::"+ sysProps.getProperty("http.proxyHost"));
          System.out.println("proxyPort::"+ sysProps.getProperty("http.proxyPort"));
  
          MMSService service = null;
          MMSPortType port =   null;
  
          try{
              System.out.println("before..");
              service = new MMSService_Impl("http://XXX.XX.X.XX/MMS/Service?wsdl");
              System.out.println("after..");
              if(service==null)
                  System.out.println("NULL SERVICE");
              System.out.println("got service...");
               port = service.getMMSServicePort();
              if(port==null)
                  System.out.println("NULL PORT");
          }
          catch(ServiceException svcEx)
          {
              System.out.println("In ServiceXexception");
          }
  
          List credProviders = new ArrayList();
          System.out.println("After cred");
  
          String clientCertFile = "F:/client-cert.der";
          String keyFile = "F:/client-key-pkcs8.der";
  
  
          String username = "userName" ;
          String password = "Password" ;
  
          CredentialProvider cp = new ClientBSTCredentialProvider(clientCertFile, keyFile);
  
          credProviders.add(cp);
  
          System.out.println("credProviders:"+credProviders);
          System.out.println("cp:"+cp+":");
  
          String strret= "";
          try{
  
  
              cp = new ClientUNTCredentialProvider(username, password);
              credProviders.add(cp);
              Stub stub = (Stub)port;
              System.out.println("before");
              stub._setProperty(WSSecurityContext.CREDENTIAL_PROVIDER_LIST, credProviders);
              System.out.println("after");
              stub._setProperty(WSSecurityContext.TRUST_MANAGER,
                  new TrustManager()
                  {
                      public boolean certificateCallback(X509Certificate[] chain, int validateErr)
                      {
                          return true;
                      }
                  }
              );
  
          String strArg = "Parameters";
          strret = port.sendData(strArg); 
  
          }
          catch(Exception e)
          {
              System.out.println("JJJ");
              e.printStackTrace();
          }           
          System.out.println("strret:"+strret);
  }
  }
  </code></pre>
  
  <p>and also .pfx format client certificate and .key file .
  So using WSE3.0 i try to consume the service like below</p>
  
  <pre><code>  WebReference.MMSServiceWse wse = new MMSServiceWse();
          UsernameToken token = new UsernameToken("XXXX", "XXXX",             PasswordOption.SendPlainText);
          wse.RequestSoapContext.Security.Tokens.Add(token);
          X509Certificate2 cert = new X509Certificate2(@"D:\\certificate.pfx","",X509KeyStorageFlags.MachineKeySet);
          wse.ClientCertificates.Add(cert);
          wse.SetPolicy("ClientPolicy");
          //System.Net.ServicePointManager.CertificatePolicy =new      TrustAllCertificatePolicy();
          String strArg = "Param";
         strArg= wse.sendData(strArg);
  </code></pre>
  
  <p>but i have got exception.</p>