[英]How do I reference an input field in another project in WCF asp.net?
我有2個項目在解決方案中。 一個叫做RentalService,另一個叫做RentalClient。
我正在嘗試使用RentalClient輸入數據(費率,天數),該數據將發送到RentalService進行處理,並通過將費率乘以天數來返回Price。
以下是該服務的代碼:
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;}
}
}
這是服務代碼:我沒有完成,因為我很困惑:/
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
}
}
我正在嘗試使用RentalClient輸入數據(費率,天數),該數據將發送到RentalService進行處理,並通過將費率乘以天數來返回價格
您需要定義一個接受Rate
和Days
作為參數的方法。 在接口ICalcPrice
定義該方法,並在類CalcPrice
定義實現
[ServiceContract]
public interface ICalcPrice
{
[OperationContract]
CalcPrice CalculatePrice(double price);
[OperationContract]
CalcPrice CalculatePrice(double price, int days);
}
然后在您的課程中:
public class CalcPrice : ICalcPrice
{
public CalcPrice CalculatePrice(double price, int days)
{
//your logic
}
每次在服務器端對合同進行更改時,請不要忘記在客戶端上更新引用。
這將為您建立一個新的wsdl,其中將包含您合同的更新。 之后,您將可以對2個參數使用CalculatePrice方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.