Unable to communicate with web service using Apache Axis2 - web-services

I have a web service hosted on a Windows Server which I can connect to with .net code and I am trying to gain access using Apache Axis2. I have been working with clj-soap which isn't being maintained but appears moderately stable.
Connecting to the service endpoint works ie (soap/client-fn service-address) but whenever I attempt to call a function Axis2 gives this exception:
org.apache.axis2.transport.http.HTTPSender sendViaPost
Unable to sendViaPost to url[MY-URL]
org.apache.axis2.AxisFault: Transport error: 404 Error: Not Found
Through some googling I've ran across things like this, which tells me that Windows is requiring some authentication or proxy configuration. I'm not sure what kind of authentication the server requires. The .net code does not authenticate with a password, so I am at a loss.
I'm looking for some help determining what information to give Axis2 to pass along to the server so my program can communicate with the web service.
The C# code is provided below, as a reference. It uses the ServiceModel library.
class Program {
private static MyService CreateServiceChannel () {
BasicHttpBinding binding = new BasicHttpBinding ( BasicHttpSecurityMode.Transport );
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
binding.MaxReceivedMessageSize = 204003200;
binding.ReaderQuotas.MaxArrayLength = 2147483647;
binding.ReaderQuotas.MaxStringContentLength = 2147483647;
EndpointAddress address = new EndpointAddress ( "https://...service.svc" );
ChannelFactory<MyService> channelFactory = new ChannelFactory<MyService> ( binding, address );
MyService channel = channelFactory.CreateChannel ();
return channel;
}
static void Main ( string[] args ) {
Console.WriteLine ( CreateMyChannel ().CallFunction ( 1 ) );
}
}

Related

Using soap services(.asmx) with Azure Service fabric

I am migrating my existing services to Azure service fabric. My existing application support the soap service(asmx) for the legacy users. I want to use the same web service as part of my microservice. That web service test.asmx(say) can be called from Rest Apis as well(If soln is there). But I'm not finding any way to use the soap service as part of Azure service fabric microservice approach. Help me out of possible solutions for tackling the web service scenario. Thanks!
I recommend converting your ASMX service into a WCF service with a BasicHttpBinding. You can then host your WCF service inside a stateless SF service, like shown here.
private static ICommunicationListener CreateRestListener(StatelessServiceContext context)
{
string host = context.NodeContext.IPAddressOrFQDN;
var endpointConfig = context.CodePackageActivationContext.GetEndpoint("CalculatorEndpoint");
int port = endpointConfig.Port;
string scheme = endpointConfig.Protocol.ToString();
string uri = string.Format(CultureInfo.InvariantCulture, "{0}://{1}:{2}/", scheme, host, port);
var listener = new WcfCommunicationListener<ICalculatorService>(
serviceContext: context,
wcfServiceObject: new WcfCalculatorService(),
listenerBinding: new BasicHttpBinding(BasicHttpSecurityMode.None),
address: new EndpointAddress(uri)
);
return listener;
}

Websphere App Server mutual SSL - obtain CN from client certificate authentication

What I have:
WAS traditional 9.0 with EJB web service;
webservice client - java application;
SSL configured for only 9449 port as described here (one way http://www.ibm.com/developerworks/webservices/tutorials/ws-radsecurity3/ws-radsecurity3.html)
I need SSL mutual authentication, so I go to Quality of protection (QoP) settings, and set Client authentication = Required.
Up to this point all works fine.
Problem is that my EJB application needs client certificate's common name to obtain a user ID, which it will use in business logic. And here I failed.
Code snippet (web service side):
MessageContext context = wsContext.getMessageContext();
HttpServletRequest req = (HttpServletRequest)context.get(MessageContext.SERVLET_REQUEST) ;
System.out.println("!! isSecure " + req.isSecure());
X509Certificate[] certificates = (X509Certificate[]) req.getAttribute("java.servlet.request.X509Certificate");
if (null != certificates && certificates.length > 0) {
...
} else {
System.out.println("!! Empty certificates");
}
isSecure returnd true, but I get "Empty certificates" message.
My guess is maybe the reason is in following. When I output the SSL configuration used on 9449 port, the first line is "com.ibm.ssl.clientAuthenticationSupported = false" while through Admin Console it is set as Required.
com.ibm.websphere.ssl.JSSEHelper jsseHelper = com.ibm.websphere.ssl.JSSEHelper.getInstance();
java.util.Properties props = jsseHelper.getProperties("WebServiceConfigure");
System.out.println("!!! WebServiceConfigure = " + props.toString());
You might want to try the "direct connect" certificate properties. This was created to address intermediate (SSL-terminating) proxies (like a web server with plug-in) that issued a certificate different than the ultimate client. This property is
com.ibm.websphere.ssl.direct_connection_peer_certificates
You can determine whether you're getting the certificate from direct connect peer or proxied peer via com.ibm.websphere.webcontainer.is_direct_connection.
See also: WAS 9 doc page.

Glassfish 3.1.2.2: #WebServiceProvider deployment fails: DPL5041 : Unknown port-component-name

I am having problems to get a #WebServiceProvider web service deployed in Glassfish 3.1.2.
I configured the glassfish-ejb-jar.xml the following way for my service.
<ejb>
<ejb-name>TestWebService</ejb-name>
<webservice-endpoint>
<port-component-name>TestWebService</port-component-name>
<endpoint-address-uri>HEAD/TestWebService</endpoint-address-uri>
<transport-guarantee>NONE</transport-guarantee>
</webservice-endpoint>
</ejb>
The web service is implemented as follows.
package test.ws.services;
import [...left out for brevity...]
#WebServiceProvider(
targetNamespace = "http://ws.test.com"
, serviceName = "HEAD/TestWebService"
, portName = "TestServicePort")
#ServiceMode(value = Service.Mode.PAYLOAD)
#Stateless
#HandlerChain(file = "test_handlers.xml")
#Interceptors({ TestInterceptor.class })
public class TestWebService implements Provider<Source> {
#WebMethod
public Source invoke(Source request) {
return calcResponseSource(request);
}
}
When starting the glassfish server the following error is shown in the glassfish server.log.
SEVERE javax.enterprise.system.tools.deployment.org.glassfish.deployment.common DPL5041:Unknown port-component-name TestWebServiceService port, all sub elements will be ignored
WARNING javax.enterprise.system.tools.deployment.org.glassfish.deployment.common DPL8007: Unsupported deployment descriptors element endpoint-address-uri value HEAD/TestWebService
WARNING javax.enterprise.system.tools.deployment.org.glassfish.deployment.common DPL8007: Unsupported deployment descriptors element transport-guarantee value NONE
Later on the service gets deployed at a "technical" URL showing the fully qualified class name.
INFO javax.enterprise.webservices.org.glassfish.webservices WS00019: EJB Endpoint deployed
server listening at address at http://test:10280/HEAD/TestWebService/test.ws.services.TestWebService
I searched the web, but could not find any solution for setting up the glassfish server to do a deployment without errors.
PS: This problem also seems to stop me from enabling HTTPS for the web service.
Regards
Egbert

Accessing WSO2 ESB proxy in java program

I have configured one wsdl proxy for external wsdl in WSO2 esb. Its successfully created proxy. While creating proxy, I have not selected Publish Same Service Contract check box. If we are consuming external web services, is it mandatory to check? When I click on try it, it is not showing operations which are available in wsdl.
If at all the above issues gets solved, we need to access the proxy from our java project. How can we access WSO2 ESB proxy in our java program?
Thanks in advance.
Thanks,
Raghu
Yes you need to check Publish Same Service Contract if you want to publish the same WSDL.
in java code you can write a simple axis2 client like shown below. To the enxpoint of your proxy.
public OMElement sendReceive(OMElement payload, String endPointReference, String operation)
throws AxisFault {
ServiceClient sender;
Options options;
OMElement response = null;
try {
sender = new ServiceClient();
options = new Options();
options.setTo(new EndpointReference(endPointReference));
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED, Boolean.FALSE);
options.setTimeOutInMilliSeconds(45000);
options.setAction("urn:" + operation);
sender.setOptions(options);
response = sender.sendReceive(payload);
} catch (AxisFault axisFault) {
throw new AxisFault("AxisFault while getting response :" + axisFault.getMessage(), axisFault);
}
Assert.assertNotNull(response);
return response;
}
You can get the sample payload by tying a tool like soap UI.
Thank You,
Dharshana.
Try like this:
CentralUuidService service = new CentralUuidService(new URL("http://wls02.tigeritbd.com:8280/services/CentralUuidService?wsdl"),new QName("http://bean.service.uuid.gov.bd/", "CentralUuidService"));
GetBirthPlaceServiceResponse response = service.getCentralUuidServiceHttpSoap11Endpoint().getBirthPlace(request);
if(response != null) {
System.out.println("Operation status is:"+response.isOperationStatus());
}
}

Consuming a web service through an internet proxy server, using a WCF client in C#; providing proxy server authentication

I have a client program that consumes a web service. It works quite well in a number of installations. Now I have a situation where a new customer connects to the internet via a proxy server, and my program's attempt to access the web service gets the "HTTP status 407: Proxy authentication required" error.
I thought that all the configuring of internet access, including proxy server address, port number and authentication would be done in the Control Panel Internet Options, and that I wouldn't have to worry about that in the code, or even in the app.config, of the Web Service client.
Have I got it all wrong?
What I have done in the mean time is give the user the chance to configure the proxy user name and password, and then in my code I do the following:
webServiceClient.ClientCredentials.UserName.UserName = configuredUsername;
webServiceClient.ClientCredentials.UserName.Password = configuredPassword;
But I don't know that this is the right thing. Because it seems to me that the above ClientCredentials would refer to the web service binding/security, not to the internet proxy server.
I suppose I can try it at the customer, but I'd rather be sure of what I'm doing first.
I found out how to do this thing, with the help of a contributor to another forum which in the flurry of trying all sorts of things I've forgotten. So thank you to that now forgotten person.
Here's the code that worked in the end (suitably disguised, but gives the right idea):
BasicHttpBinding binding = new BasicHttpBinding("APISoap"); /* APISoap is the name of the binding element in the app.config */
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Basic;
binding.UseDefaultWebProxy = false;
binding.ProxyAddress = new Uri(string.Format("http://{0}:{1}", proxyIpAddress, proxyPort));
EndpointAddress endpoint = new EndpointAddress("http://www.examplewebservice/api.asmx");
WebServiceClient client = new WebServiceClient(binding, endpoint);
client.ClientCredentials.UserName.UserName = proxyUserName;
client.ClientCredentials.UserName.Password = proxyPassword;