views:

153

answers:

0

I'm creating my first RESTful web service with Visual Studio/WCF and found a problem on the client site.

On the web service I have an interface with this function definition:

[OperationContract]
[WebGet(UriTemplate = "/test/academias/{hashAcademia}", ResponseFormat = WebMessageFormat.Json)]
Academia GetAcademiaByHash(string hashAcademia);

Then to create the client, I started a new WPF Project, used the Add Service menu and it generated an interface for my service on the file Reference.cs with this definition:

[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IManager/GetAcademiaByHash", ReplyAction="http://tempuri.org/IManager/GetAcademiaByHashResponse")]
ORM.Academia GetAcademiaByHash(string hashAcademia);

The problem is that when I call my service from the client I got an error saying that the endpoint "GetAcademiaByHash cannot be found. The only way I found the solve this was to add a [WebGet] annotation to the Interface on the client program, so the interface now looks like this:

[WebGet(UriTemplate = "/test/academias/{hashAcademia}", ResponseFormat = WebMessageFormat.Json)]
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IManager/GetAcademiaByHash", ReplyAction="http://tempuri.org/IManager/GetAcademiaByHashResponse")]
ORM.Academia GetAcademiaByHash(string hashAcademia);

So far so good, now the client can call the web service. But every time I need to update the service reference on the client, Visual Studio recreates the Reference.cs file and I lost my changes. I need to go the every function reference on the interface and add the [WebGet] annotations again.

Is there a way to avoid to have to edit Reference.cs manually and have Visual Studio generate the right function endpoints for my web service?

Thanks