[英]How do I reference an input field in another project in WCF asp.net?
I have 2 projects in a solution. 我有2个项目在解决方案中。 One called RentalService and one called RentalClient.
一个叫做RentalService,另一个叫做RentalClient。
I'm trying to use the RentalClient to input data (Rate, Days) which will be sent to RentalService to be processed and return Price by multiplying rate by days. 我正在尝试使用RentalClient输入数据(费率,天数),该数据将发送到RentalService进行处理,并通过将费率乘以天数来返回Price。
Here is the code behind for the service: 以下是该服务的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace RentalService
{
[ServiceContract]
public interface ICalcPrice
{
[OperationContract]
CalcPrice CalculatePrice(double price);
}
[DataContract]
public class CalcPrice
{
[DataMember]
public double Rate {get; set;}
[DataMember]
public int Days {get; set;}
[DataMember]
public double price {get; set;}
}
}
and here is the service code: I didn't complete it because I'm stumped :/ 这是服务代码:我没有完成,因为我很困惑:/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using RentalClient;
namespace RentalService
{
public class CalcPrice : ICalcPrice
{
public txtRate.text
}
}
I'm trying to use the RentalClient to input data (Rate, Days) which will be sent to RentalService to be processed and return Price by multiplying rate by days
我正在尝试使用RentalClient输入数据(费率,天数),该数据将发送到RentalService进行处理,并通过将费率乘以天数来返回价格
You need to define a method which accepts Rate
and Days
as parameter. 您需要定义一个接受
Rate
和Days
作为参数的方法。 Define that method in your interface ICalcPrice
and the implement in your class CalcPrice
在接口
ICalcPrice
定义该方法,并在类CalcPrice
定义实现
[ServiceContract]
public interface ICalcPrice
{
[OperationContract]
CalcPrice CalculatePrice(double price);
[OperationContract]
CalcPrice CalculatePrice(double price, int days);
}
Then in your class: 然后在您的课程中:
public class CalcPrice : ICalcPrice
{
public CalcPrice CalculatePrice(double price, int days)
{
//your logic
}
Each time you make changes on your contract on your server-side, don't forget to update your references on your client side. 每次在服务器端对合同进行更改时,请不要忘记在客户端上更新引用。
This will build you a new wsdl, which will contain the updates of your Contract. 这将为您建立一个新的wsdl,其中将包含您合同的更新。 After this you will be able to use your CalculatePrice method with 2 params.
之后,您将可以对2个参数使用CalculatePrice方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.