Skip to main content

Java Client with WCF Service using wsHttpBinding and UserName credentials

6 replies [Last post]
hardik_acharya
Offline
Joined: 2009-08-04
Points: 0

Hello,

I am new to Java. I am trying to develop a java client which can consume WCF web service (hosted on IIS).

Following is the summary of settings in WCF web service.
Binding = wsHttpBinding
Security Mode = Message
Client credentials = UserName

I want to supply user name and password dynamically inside the code.

I am using following environment
1. NetBeans IDE 6.5.1 (Build 200903060201)
2. GlassFish V3 Prelude (installed Metro Web service stack 1.4 using this link: http://weblogs.java.net/blog/bhaktimehta/archive/2008/11/working_with_me...)
3. WCF Service using Microsoft Dot Net framework 3.5 (VS2008)

I have created certificate using makecert command and then imported in keystore using keytool.exe
[Referring this link: http://blog.csdn.net/marvion/archive/2009/03/23/4015785.aspx]

While running this in java client I am getting following errors

In java client
1. Client machine is different then server machine
The server sent HTTP status code 502: Proxy Error (The specified network name is no longer available.)

2. Client and server on same machine
java.net.SocketException: Connection reset
javax.xml.ws.WebServiceException: java.net.SocketException: Connection reset
In WCF Service log:
System.ServiceModel.ActionMismatchAddressingException, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

The SOAP action specified on the message, '', does not match the HTTP SOAP Action, 'http://tempuri.org/IJAX/TestHello'.

The system works properly with .Net client but it is not working with java client.

I checked that it works if I use basicHttpBinding also but not working with wsHttpBinding.

I am attaching WCF server code and java client code. Could anyone please point my mistake?

Thanks in advance.
Hardik

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
yaronn02
Offline
Joined: 2008-03-15
Points: 0

On the same machine, configure WCF tracing & logging and compare the request sent by the WCF and WSIT clients.

[a]http://webservices20.blogspot.com/[/a]
Web Services Security and Interoperability Blog

hardik_acharya
Offline
Joined: 2009-08-04
Points: 0

Hello Yaron,

Thanks for your reply. I have checked many of your previous articles in this regards.

I also tried comparing the message entries, but found that while running java client:
(1) Only entries related to query string=wsdl is logged.
(2) No new entry is created for action (which is created in case of .net client)

Further digging in this problem, I have done following changes.

Java Client
Started use of AddressingFeature in this way
org.tempuri.IService1 port = service.getWSHttpBindingIService1(new AddressingFeature(true,true));

WCF web.config:
Set establishSecurityContext="false"

Now I am getting following exception in java client

An error occurred when verifying security for the message.
javax.xml.ws.soap.SOAPFaultException: An error occurred when verifying security for the message.
at com.sun.xml.internal.ws.fault.SOAP12Fault.getProtocolException(SOAP12Fault.java:210)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:111)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:108)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:107)

I have also checked this link for the exception and confirmed that we are using V3: http://webservices20.blogspot.com/2008/10/java-wcf-web-services-interope...

But I could not understand this line “if we could change the SOAP to have “v3” instead of “v1” everything would have worked.”

Could you help me to solve this issue?

Thanks a lot
Hardik

yaronn02
Offline
Joined: 2008-03-15
Points: 0

For the last error it seems some sort of a message was sent on the wire.
Vrify WCF logging is configured for logging both at service and transport levels.
You can also use a tool like Fiddler.
Also configure WCF trace so you can see any server side errors.

http://webservices20.blogspot.com/
Web Services Performance, Interoperability And Testing Blog

hardik_acharya
Offline
Joined: 2009-08-04
Points: 0

Hello Yaron,

Thanks again for your reply.

I am still struggling with the issue. May be my knowledge about java and java certificate store is not accurate.

Is there any way where I can verify my JKS certificate with the windows certificate store certificate?

I have created certificate using makecert command and then imported in keystore using keytool.exe [Referring this link: http://blog.csdn.net/marvion/archive/2009/03/23/4015785.aspx]

Will that be possible for you to provide any link which contains working sample similar to my requirements?

Thanks a lot,
Hardik

yaronn02
Offline
Joined: 2008-03-15
Points: 0

You need to understand what is exactly the error.

Configure WCF full logging and tracing and check the error and messages there.

ssigabudeen
Offline
Joined: 2012-04-03
Points: 0

Hi Yaron,

Looking for your help.
I need to consume WCF service(wsHttpBinding) enabled through jax-ws/axis
client. I tried with the proxy classes created through JAX-WS, got the error
message "javax.xml.ws.soap.SOAPFaultException: An error occurred when verifying security for the message."

Service service = new Service(urlAddress);
IService iService = service.getWso2InteropBindingIService(new AddressingFeature(true, true));
BindingProvider bp = (BindingProvider) iService;
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
address);
iService.getData(10);

Thanks & Regards
Jawahar