[英]Overloading method in webservice c#
I have overloaded methods in one Webservice as below: 我在一个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;
}
But when I try to consume this webservice, the method SendTransaction appears with another name: SendTransaction and SendTransaction1 但是当我尝试使用此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);
Is it possible to create overloaded methods and consume it with the same name? 是否可以创建重载方法并使用相同名称使用它? Can the problem be because of SoapHeader?
问题可能是因为SoapHeader吗? By the way, I already have webServiceBinding with WsiProfiles.None:
顺便说一句,我已经有了带有WsiProfiles.None的webServiceBinding:
[WebServiceBinding(ConformsTo = WsiProfiles.None)]
If you are using SOAP you cant , Method names must have unique names in the exported WSDL. 如果使用的是SOAP,则不能使用, 方法名称在导出的WSDL中必须具有唯一的名称 。
Depending on the technology you are using there are different ways to specify a method name. 根据您使用的技术,有不同的方法来指定方法名称。 For example in WCF you could use the [OperationContract] attribute to specify a name .
例如,在WCF中,您可以使用[OperationContract]属性来指定名称。
else method overloading is easily implemented in web service class . 否则,方法重载很容易在Web服务类中实现。 Please follow the link to have a look : -
请点击链接查看:-
https://www.codeproject.com/kb/webservices/overloadinginwebservice.aspx https://www.codeproject.com/kb/webservices/overloadinginwebservice.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.