为什么我的ASP C#WCF服务不工作?
问题描述:
我正在为一所学校的项目工作,我需要创建一个WCF服务,我可以在我的原始解决方案中使用它。为什么我的ASP C#WCF服务不工作?
我通过转到文件 - >新建项目 - > WCF服务应用程序(添加到解决方案)创建了服务,然后通过在Assignment8解决方案和新引用下右键单击References来添加服务引用。然后我发现解决方案中的服务并添加了产品服务。
我目前得到错误:UpdateProduct.aspx.cs上发生在Button1_Click的方法中的if语句行
'Assignment8.Product.ProductClient' does not contain a definition for 'UpdateProduct' and no extension method 'UpdateProduct' accepting a first argument of type 'Assignment8.Product.ProductClient' could be found (are you missing a using directive or an assembly reference?)
错误。我究竟做错了什么?
这里是我的文件:
IProduct.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace ProductService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IProduct
{
[OperationContract]
string GetData(int value);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
[OperationContract]
Boolean UpdateProduct(int productID, string productName, string productDescription, decimal productPrice, decimal productCost);
// TODO: Add your service operations here
}
// Use a data contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";
[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
}
Product.svc
<%@ ServiceHost Language="C#" Debug="true" Service="ProductService.Product" CodeBehind="Product.svc.cs" %>
Product.svc.cs
个using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace ProductService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
// NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
public class Product : IProduct
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
public bool UpdateProduct(int productID, string productName, string productDescription, decimal productPrice, decimal productCost)
{
return false;
}
}
}
UpdateProduct.aspx.cs
protected void Button1_Click(object sender, EventArgs e)
{
using (Product.ProductClient orderproxy = new Product.ProductClient())
{
if(orderproxy.UpdateProduct(Request.QueryString["ID"], txtProductName.Text, txtProductName.Text, txtProductDescription.Text, Convert.ToDecimal(txtProductPrice.Text), Convert.ToDecimal(txtProductCost.Text))){
Response.Redirect("~/ProductList.aspx");
} else {
lblStatus.Text = "The product could not be updated.";
}
}
}
答
UpdateProduct中的函数定义只需要5个参数,但在你的电话你逝去的6个参数