Windows Phone 7 network programming call WCF Service

Source: Internet
Author: User

I. Introduction to WCF Service

Windows Communication Foundation is a distributed communication programming framework provided by Microsoft to build service-oriented applications, developers can build cross-platform, secure, reliable, and enterprise-level interconnected application solutions that support transaction processing. Microsoft integrated Microsoft Distributed applicationsProgramMany mature technologies in development, such as enterprise Sevices (COM +),. Net remoting, and Web
Service (asmx), WSE, and MSMQ message queues.

Communication scope: Cross-process, cross-machine, cross-subnet, enterprise network, or Internet;

HOST: It can be ASP. NET (IIS or was), EXE, WPF, Windows Forms, NT Service, COM +;

Communication Protocol: TCP, HTTP, cross-process, and custom.

Ii. Create a WCF Service

The following shows how to set up a WCF Service and output a string.

Step 1: Open Visual Studio 2010 to create a WCF Service Application.

 
Step 2: Modify the service1.svc and iservice1.cs files.

The default file directory of the created project is as follows:

Add a method to service1.svc

Public String hellowcf ()
{
Return "Hello WCF ";

}

Add an interface to iservice1.cs:

[Operationcontract]
String hellowcf ();

Step 3: create a virtual directory of the website pointing to the project of WCF.

Find the Internet information manager in the control panel and open it. Create a virtual directory under the default web site node and name it WCF. The path points to the Web application in this example.CodeAnd click OK.

3. Call the WCF Service

Step 1: Add a reference to the WCF Service in the Windows Phone project to generate a proxy.

A servicereferences. clientconfig file is generated after the reference is successful. The file is as follows:

<Configuration>

<System. servicemodel>

<Bindings>

<Basichttpbinding>

<Binding
Name = "basichttpbinding_iservice1"
Maxbuffersize = "2147483647"

Maxcompute edmessagesize = "2147483647">

<Security
Mode = "NONE"/>

</Binding>


</Basichttpbinding>

</Bindings>
<Client>

<! -- Http: // localhost/WCF/service1.svc refers to the address of the WCF Service -->
<Endpoint address = "http: // localhost/WCF/service1.svc"
Binding = "basichttpbinding"
Bindingconfiguration = "basichttpbinding_iservice1"
Contract = "wcfservice. iservice1"
Name = "basichttpbinding_iservice1"/>
</Client>
</System. servicemodel>

</Configuration>

Step 2: Call the WCF Service.
Wcfdemo. wcfservice. service1client proxy = new wcfservice. service1client ();
Proxy. hellowcfcompleted + = new eventhandler <wcfservice. hellowcfcompletedeventargs> (proxy_hellowcfcompleted );
Proxy. hellowcfasync ();

 
Void proxy_hellowcfcompleted (Object sender,
Wcfservice. hellowcfcompletedeventargs E)
{
Textblock1.text = E. Result. tostring ();
}

XAML code

<Grid X: Name = "contentpanel" grid. Row = "1"
Margin = "12, 0, 12
<Textblock
Height = "63" horizontalalignment = "left"
Margin = "60, 47," name = "textblock1" text = ""
Verticalalignment = "TOP" width = "249"/>
</GRID>

Running effect:

Related Article

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.