I wanted  to consume  a  java webservice, so I wrote a WCF client to consume the service. I thought Java -.Net  interinteroperability would be easy with WCF, not so easy. 

The Java Web Service used WS-Security and required a UserNameToken passed as clear text.  The below code snippet  from Hanselman's blog will solve the problem, but there is a catch . This will work only if the endpoint address is on SSL. Ofcourse, WCF will not allow you to pass UserNameToken ( username & password) as clear text on http. It has to passed on https protocol, only then it will work . 

            

public void WCFMethod()
{

    WSHttpBinding myBinding = new WSHttpBinding();
    myBinding.Security.Mode 
        = SecurityMode.TransportWithMessageCredential;
    myBinding.Security.Message
    .ClientCredentialType = MessageCredentialType.UserName;
    myBinding.Security
    .Message.EstablishSecurityContext = false;

    myBinding.Security
    .Message.NegotiateServiceCredential = false;

    BindingElementCollection elements = myBinding.CreateBindingElements();
    elements
    .Find<SecurityBindingElement>().IncludeTimestamp = false;

    elements
    .Find<TextMessageEncodingBindingElement>()
    .MessageVersion = MessageVersion.Soap11;
    CustomBinding newBinding = new CustomBinding(elements);
    FooPortTypeClient svc = 
    new FooPortTypeClient(newBinding, 
    new EndpointAddress("https://javawebservice.com/service"));
}
 
 

 So, I had to go apply SSL on the webservice, to get this done. I digged more & was wondering if I could create a custom binding by getting my hands dirty. It turned out, there is already an open source custom binding, luckily I stumbled on  Yaron Naveh's  blog. He has writtern Clear Username Binding to solve the problem and is  hosted ongoogle code.  I hope this helps others like me. I used this binding get authenticated on http using WS-Security.

 

posted on Thursday, October 22, 2009 4:16 PM | Filed Under [ .NET Framework WCF C# ]

Comments

Gravatar
# re: WCF - WS Security - Java
Posted by GLASSKaryn20
on 6/1/2010 2:00 AM
All people deserve very good life time and credit loans or just consolidation loan would make it much better. Because freedom bases on money.
Gravatar
# re: WCF - WS Security - Java
Posted by LeblancAna34
on 6/8/2010 3:10 PM
Don't cry since it's ended. Smile because it arise. Our phenomenal online essays will assist you in any condition! Actually call us and we will be glad to assist you!
Gravatar
# re: WCF - WS Security - Java
Posted by MorseGilda25
on 6/13/2010 7:53 AM
I opine that you must share the recommendations just about dissertation proposal referring to this good post completing. Because some people do not really understand the proper way to do this and always take a support of the thesis writing service.
Post Comment
Title *
Name *
Email
Url
Comment *
Please add 6 and 7 and type the answer here: