For references to WCF, the difference between adding a service and adding a Web service

Source: Internet
Author: User

Original: Reference to WCF, the difference between adding a service and adding a Web service

The main content of this chapter is based on the experiments I have made to illustrate the differences between the 2 kinds of add-on services for WCF, we follow the example step by step.

The structure of the project is as follows:

The WCF service is published by the console Program (host) in the form of a host, and the bindings use Wshttpbinding. We add separately on the client side

Service Reference (Add service references) and Add Web reference (Add Web Reference) to reference the WCF service.

The following is the client code that calls the WCF method by using the service proxy that adds the service reference and adds a Web reference:

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingYingchao.Client.localhost;usingYingchao.Client.ServiceReference1;namespaceyingchao.client{classProgram {Static voidMain (string[] args) {            //Add Service reference ' s proxyService1client client =Newservice1client (); Console.WriteLine (client. GetData (111)); //Add Web reference ' s proxyService1 s =NewService1 (); Console.WriteLine (S.getdata (1234,true));        Console.read (); }    }}

Client configuration file:

<?xml version="1.0"encoding="Utf-8"?><configuration> <configSections> <sectiongroup name="applicationsettings"Type="System.Configuration.ApplicationSettingsGroup, System, version=4.0.0.0, Culture=neutral, publickeytoken= b77a5c561934e089"> <section name="Yingchao.Client.Properties.Settings"Type="System.Configuration.ClientSettingsSection, System, version=4.0.0.0, Culture=neutral, publickeytoken= b77a5c561934e089"requirepermission="false"/> </sectionGroup> </configSections> <system.serviceModel> <client> <!-- Automatically generated when you add a service reference--<endpoint address="Http://localhost:8732/service"binding="Wshttpbinding"Contract="Servicereference1.iservice1"Name="Wshttpbinding_iservice1"> <identity> <dns value="localhost"/> </identity> </endpoint> </client> </system.serviceModel> <applications Ettings> < automatically generated when adding Web service references-<Yingchao.Client.Properties.Settings> <setting n Ame="Yingchao_client_localhost_service1"serializeas="String"> <value>http://localhost:8732/service</value></setting> </Yingchao.Client.Properties.Settings> </applicationSettings></configuration>

Server-side configuration file:

<?xml version="1.0"encoding="Utf-8"?><configuration> <system.web> <compilation debug="true"/> </system.web> <system.serviceModel> <services> <service name="Yingchao.Service.Service1"> "Http://localhost:8732/service"/> </baseAddresses> ""binding="Wshttpbinding"contract="Yingchao.Contract.IService1 "><identity> <dns value="localhost"/> </identity> </endpoint> <!--Metadata Endpoints--<!--metadata Exchange endpoint For the appropriate service to introduce itself to the client. -<endpoint address="Mex"binding="mexhttpbinding"contract="IMetadataExchange"/> </service> </services> <behaviors> <serviceBehaviors> <behavior&gt          ; <servicemetadata httpgetenabled="True"/> <servicedebug includeexceptiondetailinfaults="False"/> </behavior> </serviceBehaviors> </behaviors> </system.servicemodel></conf Iguration>

After we start the service, we run the client and we see what the result is:

We see that the result of adding a Web service proxy call to WCF is not displayed, but an "Operation timed out" error occurs.

Then we change the binding of the server-side configuration file: Wshttpbinding to BasicHttpBinding, update the referenced service after compiling.

Then run the client again and we look at the results:

We see that the 2 reference services have been successfully invoked. Visible Add Web service should only use BasicHttpBinding, perhaps Microsoft is left for forward compatibility.

Then, the generated code in the Reference.cs generated by the service reference that was added separately is not the same. Adding a service reference favors WCF rules.

I looked up the information and found it to be the same as I thought. (HTTP://SOCIAL.MICROSOFT.COM/FORUMS/ZH-CN/XMLWEBSERVICESZHCHS/THREAD/808D870B-49F1-47AC-B105-4BEB580BCEC6)

For references to WCF, the difference between adding a service and adding a Web service

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.