Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to better solve the problem of WCF programming

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to better solve the problem of WCF programming, the content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.

If the machine name used in programming with WCF is not localhost, and the network allows communication on the specified port, this code works on the network. In addition, you can separate the client program from the host application and connect it through Internet.

The class of the WCF programmatic definition service is declared in the Service property, and the code file that defines the class is declared in the CodeBehind property. This directive is required to obtain the host functionality of the Web server, as described in the previous sections. Obviously, this file is not required for WCF services that are not stored on the Web server. You will learn about self-stored WCF services later in this chapter.

The data contract CompositeType is then defined in the IService1.cs file. As you can see from the code, the data contract is just a class definition that includes the DataContract attribute in the class definition and the DataMember attribute on the class members:

[DataContract] public class CompositeType {bool boolValue = true; string stringValue = "Hello"; [DataMember] public bool BoolValue {get {return boolValue;} set {boolValue = value;}} [DataMember] public string StringValue {get {return stringValue;} set {stringValue = value;}

This data contract is provided to the customer application through metadata (if you look at the WSDL file in the example, you will see this metadata). This allows the client application to define a type that can be serialized to the form, which in turn can be unordered to the CompositeType object by the service.

The client does not need to know the definition of this type; in fact, the classes used by the client can have different execution code. This simple but powerful way of defining data contracts allows the exchange of complex data structures between WCF services and their clients.

The IService1.cs file also contains a service contract, which is defined as an interface with a [ServiceContract] attribute. The WCF programming interface is also fully described in the service's metadata and can be rebuilt in the client application.

The interface members build the service's operations, each of which applies the OperationContract attribute to create an operation contract. The sample WCF programming consists of two operations, each using the previous data contract:

ServiceContract] public interface IService1 {[OperationContract] string GetData (int value); [OperationContract] CompositeType GetDataUsingDataContract (CompositeType composite);} on how to better solve the WCF programming problem is shared here. I hope the above content can be of some help and learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report