Visual Studio 2012 uses svcutil to reference a WCF service in a MVC4 client

Source: Internet
Author: User
Tags wsdl

The service has been created.

To test this service, you need to create a client and use it to invoke the service. You can do this by using the SvcUtil.exe tool from the command line using the following syntax:

svcutil.exe http://localhost:3017/mainservice.svc?wsdl

You can also access the service description as a single file:

http://localhost:3017/mainservice.svc?singlewsdl

This generates a configuration file and a code file that contains the client class. Add these two files to the client application and use the generated client class to invoke the service. For example:

class test{    staticvoid  Main ()    {        new  mainserviceclient ();         //  Use the "client" variable to invoke the operation on the service.         // always close the client.          Client. Close ();    }}

Find the Tools button on the VS Toolbar-"External Tools"-"add"

Title: SvcUtil

Command: C:\Program Files (x86) \microsoft Sdks\windows\v8.0a\bin\netfx 4.0 Tools\svcutil.exe

Initial directory: $ (ProjectDir)

Click "Apply"-"OK".

Go to the VS toolbar and find "Tools"-click on the "SvcUtil" button:

Input parameter: "HTTP://LOCALHOST:3017/MAINSERVICE.SVC?WSDL" service address.

The point "OK" will generate two files in the project root directory,

Copy the contents of the <system.serviceModel> node in the Output.config file to the last location in the </configuration> node of the Web. config file.

Called in the controller:

 PublicActionResult Index () {viewbag.message="modify this template to quickly launch your ASP. NET MVC application. "; Mainserviceclient Client=Newmainserviceclient (); //Use the "client" variable to invoke the operation on the service.             stringVALUESTR = client. GetData (1688); Viewbag.valuestr=Valuestr; //always close the client. client.            Close (); returnView (); }

Page display:

Copyright, reproduced Please specify the source: http://www.cnblogs.com/OnlyDreams/articles/4386571.html

Visual Studio 2012 uses svcutil to reference a WCF service in a MVC4 client

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.