I am consuming a webservice following the guide from this tutorial using Mono For Android using c#. Which is running perfectly fine.
Now i have created my own webservice and created a simple test method GetMyName(String Name) which is written in vb.net.
If i run this webservice from a remote machine VIA webbrowser it works fine. But its breaking on this line of code when run using Android Emulator. (This code is part of the automatically generated code Refference.cs)
public string GetMyName(string Name) {
object[] results = this.Invoke("GetMayName", new object[] {
Name});
return ((string)(results[0]));
}
I am calling my webservice like this
webserviceformobile.Service1 webservice = new webserviceformobile.Service1();
String myName = webservice.GetMyName("RIZWAN");
when i run webservice from browser it outputs the following line:
<string xmlns="http://webserviceformobile.com/">rizwan</string>
What i am doing wrong ? Is my webservice is returning data in wrong format ?
In example which is working fine i am calling webservice like this
com.cdyne.wsf.Weather we = new com.cdyne.wsf.Weather();
com.cdyne.wsf.WeatherReturn wr = new com.cdyne.wsf.WeatherReturn();
wr = we.GetCityWeatherByZIP("02138");
Can you make sure that your webservice is reachable from the emulator ? This is the exact problem that I was facing.
Related
I'm building an app with the Entity Framework on Xamarin that lets me compare some data. But when I start my "fetchdata" function, I receive the Error:
System.Data.SqlClient.SqlException (0x80131904): Snix_Connect (provider: SNI_PN7, error: 35 - SNI_ERROR_35)Snix_Connect (provider: SNI_PN7, error: 35 - SNI_ERROR_35)
I see many posts about Xamarin / Android & that it is not possible to get a connection to a SQL Server. Is there any way to fetch data from a SQL Server with .NET Core on Xamarin?
This is the string I put into SQL_Class folder with Sql_Common.cs
Fill up the brace brackets with actual parameters (removing the brace brakets too).
public static string SQL_connection_string = #"data source={server_address};initial catalog={database_name};user id={user_id};password={password};Connect Timeout={seconds}";
Then I access whenever I need it from any xamarin code just like we use in our asp.net c#
This works for me on my app without any issues.
using (SqlConnection Sql_Connection = new SqlConnection(Sql_Common.saralEHR_connection_string))
But as #Jason mentioned in his first reply, I too would get once again check the security part. I fexperienced before publishing Package to Google Play, they encrypt the App files with Hash Key Code and then only it gets upload to server
Yes it is possible (HuurrAYY!):
Im new in .net core, c# and so on and for me it was a hell of a work to get it working..
So here for the other noobs who are seeking for Help:
GuideĀ“s i used:
Building Android Apps with Entity Framework
https://medium.com/#yostane/data-persistence-in-xamarin-using-entity-framework-core-e3a58bdee9d1
https://blog.xamarin.com/building-android-apps-entity-framework/
Scaffolding
https://cmatskas.com/scaffolding-dbcontext-and-models-with-entityframework-core-2-0-and-the-cli/
How i did it:
Build your normal Xamarin app.
create new .net solution like in the tutorials (DONT WRITE YOUR Entity Framework CLASSES)
create a third solution what has to be a .net core console application
Scaffold your DB in your CONSOLE application move all created classes & folders in your "xamarin .net" solution & change the namespaces
Ready to Go!
Side Node: NuGets you need in every solution:
Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.SqlServer
[EDIT: NuGets you need in every solution]
I am doing this way (working snippet):
string connectionString = #"data source={server};initial catalog={database};user id={user};password={password};Connect Timeout=10";
string databaseTable = "{table name}";
string selectQuery = String.Format("SELECT count(*) as Orders FROM {0}", databaseTable);
try
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
//open connection
connection.Open();
SqlCommand command = new SqlCommand(selectQuery, connection);
command.Connection = connection;
command.CommandText = selectQuery;
var result = command.ExecuteScalar().ToString();
//check if there is result
if(result != null)
{
OrdersLabel.Text = result;
}
}
}
catch (Exception ex)
{
OrdersLabel.Text = ex.Message;
}
It is working fine, but API call more elegant.
I hope it helps.
I want to consume a web service in xamarin android application using soap format, below is my code:
System.Net.ServicePointManager.Expect100Continue = false;
TempConversionService.TempConvert tempConvert = new TempConversionService.TempConvert();
tempConvert.Url = "http://www.w3schools.com/webservices/tempconvert.asmx";
Button button = FindViewById<Button>(Resource.Id.MyButton);
button.Text = tempConvert.CelsiusToFahrenheit("50");
I am trying to consume a sample web service, but every time i get 403 forbidden/ 404 Not Found error can any one please let me know what is the problem
I've just tried using this service.
I added a web reference to my project, and then the following code worked
var service = new TempConvert.TempConvert();
var f = service.CelsiusToFahrenheit("50");
There's a good introduction here: http://developer.xamarin.com/guides/cross-platform/application_fundamentals/web_services/
I am creating an android client which connects to the web service and gets a response code. The problem is the android app crashes whenever I run the following code:
RequestParams params = new BasicRequestParams();
params.add("client_id", "24f8b46fc9db409012830ca264ad7bcf");
params.add("response_type", "code");
ServiceResponse response=Resting.get("http://pricewatch.ap01.aws.af.cm/api/pricewatch/oAuth/auth",80,params);
IContentData contentData = response.getContentData();
String content = (String) contentData.getContent();
JSONObject jsonObject = new JSONObject(content);
String code = (String) jsonObject.get("code");
return code;
It generates a java.lang.NullPointerException with these line:
IContentData contentData = response.getContentData();
Could someone help with these? I've been stuck with these. Thanks in advance!
I run this code many times in the emulator but never worked. However, when I run this in an android device it worked! NullPointerException happens when it doesn't get anything or any response in the server. But what I don't understand is why does this happen? Is there a difference between an emulator and an android device in terms of executing an android application?
I am a beginner in Phonegap and I made a simple web service in Microsoft Visual studio 2010 with two simple method. I want to call a method from that service from my Phonegap application for android platform. I am using xui library which method xhr is pretty much incomprehensible for me. I have read a lot of posts in that topic but I could not figure out how to do that.
My link to the web service looks like this: http://localhost/testservice/Service1.asmx.
This is my web service code:
[System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public int Calculate(int firsNumber, int secundNumber)
{
return firsNumber + secundNumber;
}
}
This is my method which should test that service:
function checkWebService() {
var url = new "http://localhost/testservice/Service1.asmx?op=HelloWorld";
x$('#test').xhr(url, {error: function(){alert("failed "+this.responseText)},
callback: function(){
alert("Success " + this.responseText);
}
});
I call this method on button click and I am always getting alert with the text "Success", without "response text".
Probably my url is wrong, but I do not know which url I suppose to type.
This is for "HelloWorld" method without parameters, and I also do not know how to call method with parameters.
Any help or explanation please.
Looking at the docs (I'm not familiar with XUI), xhr is for getting a standard web page/JSON web service, where as you are calling a standard web service which will return an XML soap response (they are XML tags not HTML). You would need to parse this response to get just the result you require.
An easy way forward would be to change your web service to return a JSON response, then use eval() in javascript to give you a "typed" view of the object. XUI Example here.
If you're new to this you might find that JQuery has a larger document/community support than XUI.
BTW "Localhost" is a loopback address that essentially means "this" computer, so even it did work it would be trying to connect to the webservice on the mobile device (or emulator) rather than your server which you would typically connect to via a URL.
I am trying out odata4j in my android app to retrieve data from a DB that can be accessed from a WCF service.
ODataConsumer co = ODataConsumer.create("http://xxx.xx.xx.xxx:xxxx/Users");
for(OEntity user : co.getEntities("Users").execute())
{
// do stuff
}
However this crashes at the call to getEntities. I have tried a variety of other calls as well, such as
Enumerable<OEntity> eo = co.getEntities("Users").execute();
OEntity users = eo.elementAt(0);
However this also crashes at eo.elementAt(0).
The logcat doesn't tell me anything, and the callstack seems to be Suspended at ActivityThread.performLaunchActivity.
Entering "http://localhost:xxxx/Users" in my web browser on the other hand works as expected and returns the users in my DB in xml format.
Any ideas on how I can debug this?
To log all http requests/responses:
ODataConsumer.dump.all(true);
The uri passed to the consumer .create call should be the service root. e.g. .create("http://xxx.xx.xx.xxx:xxxx/"); Otherwise your code looks fine.
Note the Enumerable behaves like the .net type - enumeration is deferred until access. If you plan on indexing multiple times into the results, I'd suggest you call .toList() first.
Let me know what you find out.
Hope that helps,
- john
I guess the call should be:
ODataConsumer co = ODataConsumer.create("http://xxx.xx.xx.xxx:xxxx");
for(OEntity user : co.getEntities("Users").execute())
{
// do stuff
}
create defines service you want to connect but Users is the resource you want to query.
Can you try this way.
OEntity oEntity;
OQueryRequest<OEntity> oQueryRequest= oDataJerseyConsumer.getEntities(entityName);
List<OEntity> list= oQueryRequest.execute().toList();
for (OEntity o : list) {
List<OProperty<?>> props = o.getProperties();
for (OProperty<?> prop : props) {
System.out.println(prop.getValue().toString());
}
}