PDA

View Full Version : Two methods with the same name in a WebService class


DroleDeCerfeuil
06-06-2007, 01:00 PM
Hi

I would like to expose a class as a web service which contains two methods with the same name but a different argument type (string / int). Thoose methods looks something like this :
public bool DeleteTranslation(int pIntID){
...
}

public bool DeleteTranslation(string pstrId){
...
}

When I do this, WebServiceHandlerFactory throws an exception : {"Boolean DeleteTranslation(Int32) et Boolean DeleteTranslation(System.String) utilisent tous les deux le nom de message 'DeleteTranslation'. Utilisez la propriété MessageName de l'attribut personnalisé de la WebMethod pour spécifier des noms de message uniques pour les méthodes."} (Sorry it's in french ...) It means that the two methods use the same message name.

I tried to define a custom message name using a code like this :
<object id="businessElementWebService" type="Spring.Web.Services.WebServiceExporter, Spring.Web">
<property name="TargetName" value="businessElementService" />
<property name="Namespace" value="http://iNovaShell/WebServices" />
<property name="Description" value="iNovaShell Web Services" />
<property name="MemberAttributes">
<dictionary>
<entry key="DeleteTranslation">
<object type="System.Web.Services.WebMethodAttribute, System.Web.Services">
<property name="Description" value="Delete a translation"/>
<property name="MessageName" value="OneDeleteTranslationMethod"/>
</object>
</entry>
</dictionary>
</property>
</object>
But as I thought the same exception was thrown.

I don't want to add the [WebService] and [WebMethod...] attributes to my service class...

How could I define differents Message Name for thoose methods ?? Thanks a lot.

Fred

PS: sorry for my horrible English ...

Bruno Baia
06-06-2007, 01:22 PM
Salut drôle de cerfeuil,

You did well configuring the MessageName, but with your definition, you configured both "DeleteTransaction" with the same WebMethod, so you still have the same error.


<object id="businessElementWebService" type="Spring.Web.Services.WebServiceExporter, Spring.Web">
<property name="TargetName" value="businessElementService" />
<property name="Namespace" value="http://iNovaShell/WebServices" />
<property name="Description" value="iNovaShell Web Services" />
<property name="MemberAttributes">
<dictionary>
<entry key="DeleteTranslation(string)">
<object type="System.Web.Services.WebMethodAttribute, System.Web.Services">
<property name="Description" value="Delete a translation using a string"/>
<property name="MessageName" value="DeleteTranslationWithString"/>
</object>
</entry>
<!-- this one is optional as you already changed one method -->
<entry key="DeleteTranslation(int)">
<object type="System.Web.Services.WebMethodAttribute, System.Web.Services">
<property name="Description" value="Delete a translation using an int"/>
<property name="MessageName" value="DeleteTranslationWithInt"/>
</object>
</entry>
</dictionary>
</property>
</object>



Using methods with the same name is not conform to the WS-I Basic Profiles 1.1.
It will be hard to use your web service from Java, WCF client or the WebServiceProxyFactory (Spring.Services).

If you are using .NET 2.0 and you want to be sure that your service is conform to WS-I basic profiles, you can configure the WebServiceBinding attribute :

<object id="businessElementWebService" type="Spring.Web.Services.WebServiceExporter, Spring.Web">
<property name="TargetName" value="businessElementService" />
<property name="Namespace" value="http://iNovaShell/WebServices" />
<property name="Description" value="iNovaShell Web Services" />
<property name="TypeAttributes">
<list>
<object type="System.Web.Services.WebServiceBindingAttribute, System.Web.Services">
<property name="ConformsTo" value="BasicProfile1_1"/>
</object>
</list>
</property>
<property name="MemberAttributes">
<dictionary>
<entry key="DeleteTranslation(string)">
<object type="System.Web.Services.WebMethodAttribute, System.Web.Services">
<property name="Description" value="Delete a translation using a string"/>
<property name="MessageName" value="DeleteTranslationWithString"/>
</object>
</entry>
<!-- this one is optional as you already changed one method -->
<entry key="DeleteTranslation(int)">
<object type="System.Web.Services.WebMethodAttribute, System.Web.Services">
<property name="Description" value="Delete a translation using an int"/>
<property name="MessageName" value="DeleteTranslationWithInt"/>
</object>
</entry>
</dictionary>
</property>
</object>



np with your french, you are not alone :D

HTH,
Bruno