2011-10-11 48 views
2

在.net 2.0中使用ASMX。具有相似签名的多个webmethods

代码来重现问题:

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; 
     } 
    } 
} 

我试图做的是有具有相同的签名,除了具有不同SOAPActions 2个webMethods的。上面的代码编译,但试图生成WSDL时,我得到这样一个错误:

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 wrapper 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 

上午我试图做一些错误的或不支持?任何解决方法? 我无法更改输入或输出参数的名称。目标是除SOAPAction之外具有相同的签名,如果可能的话。

谢谢。

编辑:经过一些进一步的实验后,我决定将复制方法(使用不同的SOAPAction)放在另一个.asmx文件中。

回答

3

要重载webservice中的方法,您需要提供消息名称属性,或者您可能需要删除关闭一致性检查。

[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; 
} 

而且您可以通过向service.cs文件添加以下行来关闭一致性。

[WebServiceBinding(ConformsTo = WsiProfiles.None)] 

更多细节在这里:http://msdn2.microsoft.com/en-us/library/system.web.services.webservicebindingattribute.conformsto.aspx

0

您需要提供消息的名称属性

+0

应该是一个注释。 – log0

相关问题