multiple webmethods with similar signatures
Using ASMX in .net 2.0.
Code to reproduce issue :
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
namespace TestWebService
{
public class SomeClass
{
public int Number;
}
public class SomeClassRet
{
public string AString;
}
[WebService(Namespace = "http://MyNamespace")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class MyTestService : System.Web.Services.WebService
{
[WebMethod]
[SoapDocumentMethod("http://MyNamespace/MyMeth", ParameterStyle = SoapParameterStyle.Bare, Use = System.Web.Services.Description.SoapBindingUse.Literal )]
public SomeClassRet MyMeth1(SomeClass requestParams)
{
return null;
}
[WebMethod]
[SoapDocumentMethod("http://AotherNamespace/MyMeth", ParameterStyle = SoapParameterStyle.Bare, Use = System.Web.Services.Description.SoapBindingUse.Literal )]
public SomeClassRet MyMeth2(SomeClass requestParams)
{
return null;
}
}
}
What I'm trying to do is have two webmethods that have identical signatures, except for having different SOAPActions. The above code compiles, but when trying to generate WSDL I get an error like :
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: Service 'TestWebService.MyTestService' does not conform to WS-I Basic Profile v1.1. Please examine each of the normative statement violations below. To turn off conformance check set the ConformanceClaims property on corresponding WebServiceBinding attribute to WsiClaims.None.
R2710: The operations in a wsdl:binding in a DESCRIPTION MUST result in wire signatures that are different from one another. An endpoint that supports multiple operations must unambiguously identify the operation being invoked based on the input message that it receives. This is only possible if all the operations specified in the wsdl:binding associated with an endpoint have a unique wire signature.
- Input message 'MyMeth1SoapIn' from namespace 'http://MyNamespace' has wire signature 'http://MyNamespace:requestParams'.
- Input message 'MyMeth2SoapIn' from namespace 'http://MyNamespace' has wire signature 'http://MyNamespace:requestParams'.
The Profile defines the "wire signature" of an operation in a wsdl:binding to be the fully qualified name of the child element of the soap:Body of the SOAP input message it describes. For the case of an empty soap:Body this name is an empty string. In the case of rpc-literal binding, the operation name is used as a wrap开发者_如何学JAVAper for the part accessors. In the docum...]
System.Web.Services.Description.ProtocolReflector.ReflectBinding(ReflectedBinding reflectedBinding) +557501
System.Web.Services.Description.ProtocolReflector.Reflect() +703
System.Web.Services.Description.ServiceDescriptionReflector.ReflectInternal(ProtocolReflector[] reflectors) +394
System.Web.Services.Description.ServiceDescriptionReflector.Reflect(Type type, String url) +109
System.Web.Services.Protocols.DocumentationServerType..ctor(Type type, String uri) +156
System.Web.Services.Protocols.DocumentationServerProtocol.Initialize() +284
System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response) +50
System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing) +77
[InvalidOperationException: Unable to handle request.]
System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing) +285
System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response) +183
[InvalidOperationException: Failed to handle request.]
System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response) +354
System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath) +212
System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +193
System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +93
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
Am I trying to do something wrong or not supported ? Any workarounds ? I can't change the names of the input or output parameters. The goal is to have identical signatures except for the SOAPAction, if this is possible.
Thanks.
EDIT : After some further experimentation, I've decided to put the duplicate method (with different SOAPAction) in another .asmx file.
To overload methods in webservice, either you need to provide the message name attribute or you may need to remove the turn off conformance check.
[WebMethod]
[SoapDocumentMethod("http://MyNamespace/MyMeth",MessageName="MyMeth1" ParameterStyle = SoapParameterStyle.Bare, Use = System.Web.Services.Description.SoapBindingUse.Literal )]
public SomeClassRet MyMeth1(SomeClass requestParams)
{
return null;
}
[WebMethod]
[SoapDocumentMethod("http://AotherNamespace/MyMeth",MessageName="MyMeth1Overload" ParameterStyle = SoapParameterStyle.Bare, Use = System.Web.Services.Description.SoapBindingUse.Literal )]
public SomeClassRet MyMeth2(SomeClass requestParams)
{
return null;
}
And you can turnoff the conformance by adding following line to the service.cs file.
[WebServiceBinding(ConformsTo = WsiProfiles.None)]
More details here : http://msdn2.microsoft.com/en-us/library/system.web.services.webservicebindingattribute.conformsto.aspx
you need to provide the message name attribute
精彩评论