我在一个Webservice中重载了方法,如下所示:
[SoapHeader("Authentication")]
[WebMethod(MessageName = "DeferringTransaction", Description = "Deferring Transaction")]
public WsResponse SendTransaction(WsDeferringTransaction wsDeferringTransaction)
{
factory.LoadSettings();
WsResponse response = new WsResponse();
response.ErrorCode = "Test";
response.ReturnCode = 1;
return response;
}
[SoapHeader("Authentication")]
[WebMethod(MessageName = "ProcessedTransaction", Description = "Processed Transaction")]
public WsResponse SendTransaction(WsProcessedTransaction wsProcessedTransaction)
{
factory.LoadSettings();
WsResponse response = new WsResponse();
response.ErrorCode = "Test";
response.ReturnCode = 1;
return response;
}
但是当我尝试使用此Web服务时,SendTransaction方法会出现另一个名称:SendTransaction和SendTransaction1
ServiceReference1.WsDeferringTransaction wsDeferringTransaction = new ServiceReference1.WsDeferringTransaction()
{
CaptiveId = 1,
TransactionDeferringId = 2
};
ServiceReference1.WsResponse r = ws.SendTransaction(u, wsDeferringTransaction);
ServiceReference1.WsProcessedTransaction wsProcessedTransaction = new ServiceReference1.WsProcessedTransaction()
{
DocumentNumber = 4,
TransactionSequenceNumber = 450
};
ServiceReference1.WsResponse r2 = ws.SendTransaction1(u,wsProcessedTransaction);
是否可以创建重载方法并使用相同的名称来使用它?问题可能是因为SoapHeader?顺便说一句,我已经使用WsiProfiles.None:
进行了webServiceBinding [WebServiceBinding(ConformsTo = WsiProfiles.None)]
答案 0 :(得分:2)
如果您使用的是SOAP,则方法名称必须在导出的WSDL中具有唯一名称。
根据您使用的技术,有不同的方法来指定方法名称。例如,在WCF中,您可以使用[OperationContract]属性指定名称。
else方法重载很容易在Web服务类中实现。请点击链接查看: -
https://www.codeproject.com/kb/webservices/overloadinginwebservice.aspx