Can't access webservice using Xamarin and WCF - ios

I would like to consume a public web service using Xamarin and WCF. For this demo, I'll be using Xamarin.iOS .
This is the (public) webservice I'm trying to consume:
http://www.webservicex.net/globalweather.asmx?WSDL
Inside Xamarin Studio, I add a Web Reference with the URL from the webservice. The selected Framework is set to Windows Communication Foundation (WCF).
Now, I'm using the following code to connect with the service:
var _client = new GlobalWeatherSoapClient();
_client.BeginGetWeather ("Berlin", "Germany", (ar) => {
var result = _client.EndGetWeather(ar);
}, null);
When executing this code, I'm getting a System.NullReferenceException. This is the problem, why isn't it working correct?
The strangest part: When I'm not using WCF, but select .NET 2.0 Web Services as Framework, everything seems to be working fine.
I can't see what's wrong with my WCF code - according to the docs, everything should work ok.
I hope somebody can help me out! Thanks in advance!

You are not following the docs.
Quote from that page:
To generate a proxy to a WCF service for use in Xamarin.iOS projects,
use the Microsoft SilverlightServiceModel Proxy Generation Tool
(SLSvcUtil) that ships with the Silverlight SDK on Windows. This tool
allows specifying additional arguments that may be required to
maintain compliance with the service endpoint configuration.
So, first thing is that you need to create a proxy on a Windows machine with slsvcutil. Adding WCF references to project through Xamarin Studio does not work. It only works for .NET 2.0 Web Services, that's why that option is OK.
Second thing, after you have created your proxy on Windows with slsvcutil, you need to add it to your project.
Third, you need to initialize it like this, with basic http binding (again, code from the above link):
var binding = new BasicHttpBinding () {
Name= "basicHttpBinding",
MaxReceivedMessageSize = 67108864,
};
//...
client = new Service1Client (binding, new EndpointAddress ("http://192.168.1.100/Service1.svc"));
Suggestion: forget about WCF on iOS. That article contains very useful information on other means of client-server communication.

Related

MVC Web App using Web API do not work after deploying on IIS

I have created Web application using asp.net MVC architecture.
I have used Web API for getting data from database. Both Web application and Web API are in same project. I have not published Web API separately on IIS.
When I am debugging or running the application through Visual studio it works properly. I have used below code to get data from Web API URL
TODOINfo[] lstToDoInfo = httpClient.GetAsync("http://localhost:65373/api/RESTApi").Result.Content.ReadAsAsync<TODOINfo[]>().Result;
In Above function I am passing url which consist of localhost plus fixed port number. Above code is working fine when running through in Visual studio.
I have published the same code on IIS by doing below changes.
TODOINfo[] lstToDoInfo = httpClient.GetAsync("http://" + sBaseUrl + "/api/RESTApi").Result.Content.ReadAsAsync<TODOINfo[]>().Result;
sBaseUrl value is "localhost".
After Browsing the application on internet explorer getting following error.
No MediaTypeFormatter is available to read an object of type 'TODOINfo[]' from content with media type 'text/html'.
Any information or suggestion regarding above problem is highly appreciate.
Try changing sBaseURL to "localhost/" +yourwebsite
another option would be to change: sBaseURL to: servername/yourwebsite

Query MVC Web Api from another project while running on localhost

I have a Vis Stu solution that contains many projects. Two of these projects are a
MVC Web Application (Views, JS, CSS)
MVC Web API
Since these are their own projects, I need a way to query the Web Api via my web application.
In the JS I have a function that tries to get data from the Web Api
get: function (id) {
var url = 'api/Employee/' + id;
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function (data) {
return data;
};
httpRequest.open('GET', url);
httpRequest.send();
}
If I build the Api solution and add in its localhost address to the ajax url (http://localhost:50475/api/Employee/3) I get the usually Cross Origin Not Allowed issue.
Is there a way to connect to this Api from another origin while I am in developing?
Have you tried adding an assembly reference to your project? That will make projects accessible to each other in development.
In visual studio:
1. Go to the project that needs to have access to the API project
2. Right click references
3. Add reference
4. Under Solution select the name of the project you're trying to access.
I Think its because of different ports of WebApi and MVC Projects that visual studio assigned to them by default. you can change the default port bindings, You should set one unique port for both applications. Right click on project => properties => web and set the port.

Create web service using external WSDL through Add Service Reference

I have an ASP.NET MVC3 project in .NET 4 which needs to act as a SOAP server to receive notifications from another website.
I have created web services before, but I don't know how to set up a way to receive these notifications where the WSDL is provided by the external website.
I know I can create a service and get that to produce its own WSDL, but I'm assuming there must be an easy way to add a service reference, and then create a service that uses the objects/methods generated by it.
How do I do this?
Thanks
You can use the svcutil tool from visual studio commands line, to create the required configuration and proxy files

Visual DataFlex: call WebService from the web page

I have the web service and generated class for it. I can use this generated class in windows application as it described in Help. The question is: how can I use this generated class in the web project? (the analogous actions - creating object and use its functions -, as it was in windows app, are not worked)
Visual Dataflex questions are best asked at: http://support.dataaccess.com
There are a couple of possibilities.
Your class may not be cWebService or you have not included it as part of a web project.
For web services to be available, they MUST be part of a web project. This will usually be called webapp.src.
For functions to be available to the web service, you need to decorate them as "published"
e.g.
{ Published = True }
{ Description = "SOAP Hello World function definition." }
Function HelloWorld Returns String
Function_Return "HELLO WORLD"
End_Function
Those top two lines make sure that the function is available as a SOAP or web service call.
Sorry to answer so late, I hope you've already solved it.
There's actually a tutorial section for this in the VDF Help under Tutorials > Quick Start > Consuming Your First Web Service > Consuming a Web Service in a Web Application.

Silverlight - RIA Services Data/Service issue

I have a baffling situation, which maybe you guys can help.
My RIA Solution does not retrieve the data from the service...
To give you an idea...
My domain service is derived from LinqToSqlDomainService and is in a Web Application project.
I had first created a RIA Services project with MVC and the Get query to the service (DomainContext) works great.
I then created a new RIA Solution, and used a Web Application project (instead of MVC to host the service), and this just does not get the data.
The Silverlight (RIA) client project is a copy of the working one and although I changed references, etc., I suspect there could be a problem in this project, either creating the HttpDomainClient:
this(new HttpDomainClient(new Uri("DataService.axd/FooAdmin-Web-FooDomainService/", System.UriKind.Relative)))
or in the LoadOperation:
loadOp = this._context.Load(this._context.GetFooQuery());
What are some ways, I can troubleshoot this and see what is failing?
You can use Fiddler to see the HTTP requests and possibly error codes.

Resources