Consuming ASMX web service

Topics: General Discussion Forum, July and December Releases Forum, Service Factory Modeling Edition Forum
Jul 15, 2008 at 5:51 AM
I have created a ASMX web service in WSSF. i now want to consume this web service on client side. I am unable to do it. Please if anyone could refer me some good article with sample code on this would be highly appreciated.


Faisal Shahzad
Jul 15, 2008 at 5:39 PM
Hi, assuming you have created the three models and the ASMX Implementation Project (as mentioned in this post) you should proceed as follows:

  1. MAPPING TABLE: Set the corresponding mapping table in the DataContract and ServiceContract Model. This setting can be modified by openning each model and clicking on the design surface to populate its properties. The correct value will show up once you have successfully created the Implementation Project and it will have the same name that you chose for it.
  2. VALIDATE MODELS: Make sure all models are valid by right click on their design surface and choosing Validate. Correct any errors that may be informed.
  3. GENERATE CODE: Open the DataContract model, right click on the design surface and this time, choose Generate Code. Repeat this step on the ServiceContract Model. This action will generate the code and output it in the [Solution Root] /[ImplementationProjectName]/Source/Service Interface directory. Note that code generation implicitly performs a model validation, so any pending errors on the previous step will come up in this one too and you won't be able to generate code until they are fixed. You can then write your own business logic and data access by following the recommended directory structure and invoke them by extending the partial class created on the Service Implementation Project.
  4. HOST MODEL SETTINGS: Open the Host Model and make sure that the Client and Host applications created are set with ASMX Implementation Technology and have the appropiate Implementation Project set:
    • Client Implementation Project: [Solution Root] / [ImplementationProjectName] / Tests / [ImplementationProjectName].Client
    • Host Implementation Project: [Solution Root] / [ImplementationProjectName] / Source/Service Interface / [ImplementationProjectName].Host
  5. GENERATE SERVICE: On the Host Model, navigate to the Service Reference element on the Host Applications node and click the Generate Service link displayed on the main panel. If the model is invalid, this link will be grayed out and you will have to click on Validate Model instead to correct any pending errors.
  6. LAUNCH HOST: In the Solution Explorer, navigate to the Host Implementation Project directory specified on step 4, right click on the project node and choose View in Browser. This will initialize the ASP.NET Development Server which will be used to host your service while developing.
  7. GENERATE PROXY: On the Host Model, navigate to the Proxy element on the Client Application node, click on the Generate Proxy link and follow the wizard steps. Note that this step requires the service up and running to be successful.

Once these steps have been completed, make sure the Host is still running and simply run the Client Implementation project to start testing your service. Enjoy!