J2me web service connection problem - web-services

i'm trying to connect to a php web service using kxml-rpc api and the code is as simple as this:
XmlRpcClient xmlrpc = new XmlRpcClient("http://***ip here***:88/secure/service");
Vector parameters = new Vector();
parameters.addElement("value");
String result = (String) (xmlrpc.execute("functionName", parameters));
Mobile device asks for permission to connect to GPS. But somehow the result is always null.
What can be done? and what configuration i should check?
Thanks.

Check whether the web service provider is actually invoked, and what does it return. It is not unlikely that it returns null, (so the clients gets it).

Related

WSO2 ESB Unit Testing

We've developed a Proxy Service into WSO2 ESB which is an orchestrator, and calls multiple services aggregating the response.
How can I test each single step (or mediator) of the proxy flow, and how the system reacts to each possible situation (e.g. Success, Failure, Slow response time...)?
We are trying to mock the behaviour of each service called by the proxy (with Wiremock), for each step, but we are not able to dynamically change the endpoints (or the ports) pointed by each call.
Example:
Real service is listening on port 8280
Wiremock is listening on port 8281
We need to dynamically change the endpoint within the Proxy, to let it call the Wiremock service (8281) instead of the real one (8280)
If there are other ways to test, I'm happy to explore different solutions...
I am unable to get your question correctly... can't you in Your proxy service you mention the endpoint url with port as 8281...??
Finally found the solution to the problem.
Using the endpoints of the registry, you are able to get the resources from the registry, change them and update it.
For example you could do something like:
AutomationContext esbContext = new AutomationContext("ESB", TestUserMode.SUPER_TENANT_ADMIN);
String esbSession = esbContext.login();
ResourceAdminServiceClient resourceClient = new ResourceAdminServiceClient(esbContext.getContextUrls().getBackEndUrl(),
esbSession);
String endpoint = resourceClient.getTextContent("/_system/governance/endpoints/HelloService.xml")
.replace(":8280", String.format(":%s", port));
resourceClient.updateTextContent("/_system/governance/endpoints/HelloService.xml", endpoint);

Call soap web service using HttpWebRequest in Windows Store Apps

Let me clear one thing that i don't wanna use "Add Service Reference" method. I want to call a soap service using HttpWebRequest in windows store app. I have working soap web service given by my client. I only have access to the web service but not source code. I have searched the internet but couldn't find solution for Windows store app.
Thanks in advance and Happy New Year.
Why do you want to avoid using Add Service Reference? Even so, I strongly discourage you from using HttpWebRequest directly as you will lose all the benefits of having the SOAP protocol already implemented.
You can use ChannelFactory<T>, though; even from a Windows Store app:
First create the interface from the web service WSDL using svcutil.exe:
svcutil /serviceContract http://localhost:61547/Service1.svc?wsdl
Include the generated code file in your Windows Store project.
Create the channel and call a method on it from your code:
var binding = new BasicHttpBinding();
var endpoint = new EndpointAddress("http://localhost:61547/Service1.svc");
var factory = new ChannelFactory<IService1>(binding, endpoint);
var channel = factory.CreateChannel();
var result = channel.GetData(3);
((IClientChannel)channel).Close();
I tried it out with a sample web service and it worked flawlessly.

gSOAP HTTP Authentication

I'm working with gSOAP 2.8.15 and I'm trying to implement the HTTP Authentication by following the instructions in section 19.14 of gsoap documentation (http://www.cs.fsu.edu/~engelen/soapdoc2.html#tth_sEc19.14).
The only difference is that the codes introduced in the documentation is written in C but I'am coding in C++.
Here is my codes for client side of the web service
// The variable wsp is a instance of web service proxy generated by soapcpp2.
// The proxy is a sub-class of the class soap
wsp.userid = "user";
wsp.passwd = "password";
// call the function of web service
wsp.get_version(&result);
In the server side, I use these codes to check the authentication:
// The variable wss is the a instance of web service service generated by soapcpp2.
if (wss.userid == NULL || wss.passwd == NULL)
//......
The problem is when I call the function of web service using the client-side code, the userid and passwd is always NULL in server-side. But when I call the same function using soapUI by passing the userid and passwd with preemptive authorisation mode, the server will get the information without problem.
I appreciate if anyone can help me work out the problem. Thanks for your attention.
I have used tcpdump to catch the package sent between web service server and client and I found that there is no http header sent when the client call the function of the web service. So I have done some search in the documentation of gSOAP and found this sentence:
A client may use the http:// prefix. When absent, no HTTP header is
sent and no HTTP-based information will be communicated to the
service.
It solves my problem...

Axis2 multiple connection authentication issue

I have two servlets that access two corresponding Axis2 web services on the same host. One of the servlets is read-only, while the other writes to a database.
Each of the Axis2 web services uses BASIC authentication. The read-only web service uses a system account, while the write web service uses the user's credentials (which are submitted as part of a web form).
The problem I'm running into is that the servlet called second always fails authentication to its web service. For example, I can query the read-only service through it's servlet all I want, but I get a "401: Authorization Required" when I try to use the write service. If I call the write service first, I get the same error when I try to use the read-only service.
Here is how I am setting the credentials for the connections in the servlets:
Stub service = new Stub(serviceUrl);
HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
auth.setUsername(username);
auth.setPassword(password);
auth.setPreemptiveAuthentication(true);
service._getServiceClient().getOptions().setProperty(HTTPConstants.AUTHENTICATE, auth);
The servlet that accesses the read-only service has this code in it's constructor. The servlet that accesses the write service has this code in it's doGet/doPost method.
It seems that the credentials for the first service called are getting cached somewhere, but I can't find where that could be. I saw a possible solution here, but I can't find where WSClientConstants.CACHED_HTTP_STATE is defined. The comments in this JIRA issue seems to imply that it's part of org.apache.axis2.transport.http.HTTPConstants but it's not there.
Specifics:
Axis version: 1.5.1
Tomcat Version: 6.0.26
Java version: 1.6.0_23
It turns out the connections to the two different services were using the same JSESSIONID. Thus, the connection to the second web service was trying to use a session authenticated for the first web service, causing the error.
My solution for this was to define an HttpClient for each service, done by the following
MultiThreadedHttpConnectionManager manager = new MuliThreadedHttpConnectionManager();
HttpClient client = new HttpClient(manager);
ConfigurationContext context = ConfigurationContextFactory.createDefaultConfigurationContext();
context.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, client);
context.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, true);
Stub service = new Stub(context, serviceUrl);
This allows both servlets to have a separate session for their corresponding services.
The important point is to create a dedicated ConfigurationContext.
I've solved in a simpler way using a default config context when creating the stub without the multithreaded connection factory
stub = new MyStub(ConfigurationContextFactory.createDefaultConfigurationContext(), myServicesUrl);

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;