有一个WCF Web服务和Web服务的客户端。 Web服务包含一些带有一些参数的方法。
Web服务合同:
namespace WcfPaymentRegistryService
{
[ServiceContract]
public interface UsrIPaymentRegistryService
{
#region business methos region
[OperationContract]
string TestConnection();
#endregion
#region business methos region
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped)]
[OperationContract]
string GetPaymentRegistry(string debtorName, string debtorSurname, string debtorMiddleName, DateTime dateBegin, DateTime dateEnd);
#endregion
}
}
Web服务实现:
namespace WcfPaymentRegistryService
{
public class UsrPaymentRegistryService : UsrIPaymentRegistryService
{
private string clientSection;
private string paymentSection;
#region business methos region
string UsrIPaymentRegistryService.GetPaymentRegistry(string debtorName, string debtorSurname, string debtorMiddleName,
DateTime dateBegin, DateTime dateEnd)
{
var userConnection = (UserConnection)HttpContext.Current.Session["UserConnection"];
var resultXml = "";
var selectPaymentsRegister = (Select)new Select(userConnection)
.Column("c", "Surname").As("Surname")
.Column("c", "GivenName").As("Name")
.Column("c", "MiddleName").As("MiddleName")
.Column("c", "Name").As("FullName")
.Column("c", "Phone").As("Phone")
.Column("c", "Address").As("Address")
.Column("up", "UsrPaymentSum").As("Amount")
.Column("up", "UsrPaymentDate").As("AmountDate")
.From("UsrPayments").As("up")
.Join(JoinType.Inner, "Contact").As("c")
.On("up", "UsrDebtorId").IsEqual("c", "Id")
.Where("c", "Surname").IsEqual(Column.Parameter(debtorSurname))
.And("c", "GivenName").IsEqual(Column.Parameter(debtorName))
.And("c", "MiddleName").IsEqual(Column.Parameter(debtorMiddleName))
.And("up", "UsrPaymentDate").IsGreaterOrEqual(Column.Parameter(dateBegin))
.And("up", "UsrPaymentDate").IsLessOrEqual(Column.Parameter(dateEnd))
as Select;
using (DBExecutor dbExecutor = userConnection.EnsureDBConnection())
{
using (IDataReader reader = selectPaymentsRegister.ExecuteReader(dbExecutor))
{
while (reader.Read())
{
clientSection =
"<Client>\n" +
"<Name>" + reader["Name"].ToString() + "</Name>\n" +
"<Phone>" + reader["Phone"].ToString() + "</Phone>\n" +
"<Address>" + reader["Address"].ToString() + "</Address>\n" +
"</Client>";
paymentSection +=
"<Payment>\n" +
"<Amount>"+ reader["Amount"].ToString() + "</Amount>\n" +
"<Date>" + reader["AmountDate"].ToString() + "</Date>\n" +
"</Payment>\n";
}
resultXml = "<xml>\n" + clientSection + "<Payments>\n" + paymentSection + "</Payments>\n</xml>";
}
}
return resultXml;
}
#endregion
#region common methods region
string UsrIPaymentRegistryService.TestConnection()
{
return "Test connection is successful";
}
#endregion
}
}
在方法GetPaymentRegistry(...)
中,我添加了参数DateTime dateBegin
和DateTime dateEnd
。我从WSDL生成了一个代理类,发现该方法添加了额外的参数dateBeginSpecified bool
和bool dateEndSpecified
。
如何禁用其他参数的生成?
我将非常感谢这些信息。谢谢大家。