WCF for consumption in Silverlight application (Windows Phone 8.0)

Asked

Viewed 59 times

1

I’m having trouble adding to Servicereference, it adds normally but when it will generate the class "Client" it finds 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.

When creating . svc I selected the new Silverlight compatible item. I’ve also tried to change the windows phone project to version 8.1 Silverlight but also without success. I read in some tutorials that this could be a bug of VS, but also that it had already been fixed (ie, I may be with the version of something outdated, but I’m with VS2015).

When inserting a new . svc and running it empty, it works right away, the problem starts to arise when I enter methods that return of type List<>, the weirdest thing is that the first time I created a WCF project I did the same process and it worked right away, I tried to insert this project (what worked) in 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 entering the reference I used the following settings: inserir a descrição da imagem aqui

Product class:

[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 tried to insert the [Datacontract] and [Datamembercontract] but I still didn’t succeed.

Perhaps one solution is to change the version of Silverlight in the project, but I don’t know how to do this and I also have to use version 8.0 because it is a requirement.

1 answer

1

Whenever I consume a service, I’ve never been able to put the reference on Windows Phone and work smoothly.

Now I always use Restsharp to consume any service (WCF, ASMX, Webapi, etc). 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: http://restsharp.org/

Hugs.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.