橙树的Blog

导航

XML Web Service 函数重载

1. 错误的写法

[WebService(Namespace = "http://192.192.15.131/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class UserWebService : System.Web.Services.WebService {
[WebMethod]
public string HelloWorld()
{
 return "HelloWorld";
}
 
[WebMethod]
public string HelloWorld(string name)
{
 return "HelloWorld " + name;
}

运行,提示错误:

服务“UserWebService”不符合 WS-I Basic Profile v1.1。请检查下面的每个标准化声明冲突。要关闭一致性检查,请将相应 WebServiceBinding 特性上的 ConformanceClaims 属性设置为 WsiClaims.None。
R2304: 配置文件不允许在 wsdl:portType 中进行操作名重载。说明中的 wsdl:portType 必须具有操作,且每个操作的 name 属性各不相同。注意,此要求仅适用于给定 wsdl:portType 中的 wsdl:operations。wsdl:portType 可能具有与其他 wsdl:portTypes 中发现的同名 wsdl:operations。
 -  来自命名空间“http://192.192.15.13/”的 portType“UserWebServiceSoap”上的操作“AddPerson”。
要使服务一致,请确保属于同一绑定的所有 Web 方法具有唯一名称。

2.解决方法

     通过在方法中添加一个MessageName属性,并将类的WebServiceBinding 属性中ConformsTo 指定为WsiProfiles.None。

     具体写法:

     [WebService(Namespace = "http://192.192.15.131/")]
[WebServiceBinding(ConformsTo = WsiProfiles.None)]
public class UserWebService : System.Web.Services.WebService {

[WebMethod]
public string HelloWorld()
{
 return "HelloWorld";
}
 
[WebMethod(MessageName="HelloWorldWithName")]
public string HelloWorld(string name)
{
 return "HelloWorld " + name;
}

运行结果:


UserWebService


支持下列操作。有关正式定义,请查看服务说明


此 Web 服务不符合 WS-I Basic Profile v1.1。

请检查下面每个标准化声明是否存在冲突。请按建议修正冲突,或向 <webServices> 配置节添加设置,对整个 vroot 关闭 BP 1.1 一致性警告。

要对整个 vroot 关闭 BP 1.1 一致性警告,请从应用程序配置文件的 <conformanceWarnings> 节移除“BP1.1”值:

<configuration>
<system.web>
<webServices>
<conformanceWarnings>
<remove name='BasicProfile1_1'/>
</conformanceWarnings>
</webServices>
</system.web>
</configuration>



posted on 2006-08-02 12:30  橙树的Blog  阅读(1999)  评论(0)    收藏  举报