在.net 2.0中使用ASMX。
重现问题的代码:
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;
}
}
}
我要做的是有两个具有相同签名的web方法,除了具有不同的SOAPActions。上面的代码编译,但在尝试生成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文件中。
答案 0 :(得分: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)]
答案 1 :(得分:0)
您需要提供消息名称属性