WCF for consumption in Silverlight application (Windows Phone 8.0)

1

I'm having trouble adding ServiceReference, it usually adds but when it generates the "Client" class it encounters the following error:

  

No endpoints compatible with Silverlight 3 were found. The generated   client class will not be usable unless endpoint information is   provided via the constructor.

In the creation of .svc I selected the new item with compatibility for Silverlight. I have also tried to change the project windows phone to version 8.1 Silverlight but also to no avail. I have read in some tutorials that this could be a VS bug, but also that it had already been fixed (ie, I may have the version of something outdated, but I'm with VS2015).

When inserting a new .svc and running it empty, it works out, the problem starts to appear when I insert methods that return ; the strange thing is that the first time I created a WCF project I did the same process and it worked, I tried to insert this project (what worked) in the solution and it also did not work in this case.

.SVC :

[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class CargaInicial : ICargaInicial
    {
        LojaService _lojaService = new LojaService();
        UsuarioService _usuarioService = new UsuarioService();
        ProdutoService _produtoService = new ProdutoService();

        public Loja ObterLoja()
        {
            return _lojaService.ObterLoja();
        }

        public List<Usuario> ObterUsuarios()
        {
            return this._usuarioService.ObterUsuarios();
        }

        public List<Produto> ObterProdutos()
        {
            return _produtoService.ObterTodosProdutos();
        }
    }

Interface :

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class CargaInicial : ICargaInicial
{
    LojaService _lojaService = new LojaService();
    UsuarioService _usuarioService = new UsuarioService();
    ProdutoService _produtoService = new ProdutoService();

    public Loja ObterLoja()
    {
        return _lojaService.ObterLoja();
    }
    public List<Usuario> ObterUsuarios()
    {
        return this._usuarioService.ObterUsuarios();
    }

    public List<Produto> ObterProdutos()
    {
        return _produtoService.ObterTodosProdutos();
    }
}

When I inserted the reference I used the following settings :

ProductClass:

[Table("Produto")]
public class Produto : Entity<Guid>, IProduto
{
    [Required]
    public string Codigo { get; set; }

    [Required]
    public string Descricao { get; set; }

    [Required]
    public decimal PrecoVenda { get; set; }

    [Required]
    public DateTime DataHoraUltimaAtualizacao { get; set; }
}

This class is from another project in the same solution. I have tried to insert the DataContract> and [DataMemberContract] but still failed.

Maybe a solution is to change the version of Silverlight in the project, but I do not know how to do that and I also have to use version 8.0 as it's a requirement. p>     

asked by anonymous 26.09.2015 / 17:40

1 answer

1

Whenever I consume a service, I have never been able to put the reference on Windows Phone and run smoothly.

Now I always use RestSharp to consume any service (WCF, ASMX, WebAPI, etc.). It works very well and does not need to include the service reference.

Example:

var client = new RestClient("http://example.com");
// client.Authenticator = new HttpBasicAuthenticator(username, password);

var request = new RestRequest("resource/{id}", Method.POST);
request.AddParameter("name", "value"); // adds to POST or URL querystring based on Method
request.AddUrlSegment("id", "123"); // replaces matching token in request.Resource

// easily add HTTP Headers
request.AddHeader("header", "value");

// add files to upload (works with compatible verbs)
request.AddFile(path);

// execute the request
RestResponse response = client.Execute(request);
var content = response.Content; // raw content as string

// or automatically deserialize result
// return content type is sniffed but can be explicitly set via RestClient.AddHandler();
RestResponse<Person> response2 = client.Execute<Person>(request);
var name = response2.Data.Name;

// easy async support
client.ExecuteAsync(request, response => {
    Console.WriteLine(response.Content);
});

Reference: link

Hugs.

    
29.09.2015 / 20:51