Je suis nouveau à WCF et j'apprends également le modèle de conception MVP. J'ai un projet de test avec un service WCF fonctionnel. Je suis capable de tester avec le client de test WCF et ça fonctionne bien.WCF - Appel du service WCF à partir de la couche Presenter
J'ai besoin d'aide pour appeler le service WCF à partir de ma couche Presenter et demander au Presenter de renvoyer les données à View (winforms). J'ai un Windows Form avec deux zones de texte nommées txtProductID et txtDescription. J'ai aussi un bouton nommé btnGetProductData. Je voudrais ce qui suit pour se produire:
- Je mettrai un identifiant de produit dans le domaine txtProductID.
- Je clique sur le bouton btnGetProductData et le présentateur doit appeler la méthode GetProductData à partir du service WCF et renvoyer la description du produit dans le champ txtProductDescription de mon formulaire.
Voici le code pertinent de la bibliothèque de services WCF:
IProductService.cs
------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace MyWCFServices.ProductService
{
[ServiceContract]
public interface IProductService
{
[OperationContract]
Product GetProductData(string ProductId);
}
[DataContract]
public class Product
{
[DataMember]
public string ProductID { get; set; }
[DataMember]
public string ProductDescription { get; set; }
}
}
ProductService.cs
--------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using MyWCFServices.ProductEntities;
using MyWCFServices.ProductBusinessLogic;
namespace MyWCFServices.ProductService
{
public class ProductService : IProductService
{
ProductLogic productLogic = new ProductLogic();
public Product GetProductData(string ProductId)
{
ProductEntity productEntity = productLogic.
GetProductData(ProductId);
Product product = new Product();
TranslateProductEntityToProductContractData(productEntity,
product);
return product;
}
private Product TranslateProductEntityToProductContractData(
ProductEntity productEntity, Product product)
{
product.ProductID = productEntity.ProductID;
product.ProductDescription = productEntity.ProductDescription;
return product;
}
}
}
Votre service a l'air bien, mais quel problème êtes-vous avoir sur le client, en particulier? EG: avez-vous des problèmes pour créer le proxy, cela ne retourne-t-il pas ce que vous attendiez? –