我在一个Web服务中重载了如下方法:
[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的webServiceBinding。无:
[WebServiceBinding(ConformsTo = WsiProfiles.None)]
如果您使用的是SOAP,则不能使用,方法名称在导出的WSDL中必须具有唯一的名称。
根据您使用的技术,有不同的方法可以指定方法名称。例如,在WCF中,您可以使用[OperationContract]属性来指定名称。
else方法重载在web服务类中很容易实现。请点击链接查看:-
https://www.codeproject.com/kb/webservices/overloadinginwebservice.aspx