Skip to content

apply code highlighting to WCF docs #8128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 15, 2018
6 changes: 3 additions & 3 deletions docs/framework/wcf/samples/announcements-sample.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This sample shows how to use the Announcement functionality of the Discovery fea
## Service
This project contains a self-hosted calculator service. In the `Main` method, a service host is created and a service endpoint is added to it. Next, a <xref:System.ServiceModel.Discovery.ServiceDiscoveryBehavior> is created. To enable announcements, an announcement endpoint must be added to the <xref:System.ServiceModel.Discovery.ServiceDiscoveryBehavior>. In this case a standard endpoint, using UDP multicast is added as the announcement endpoint. This broadcasts the announcements over a well-known UDP address.

```
```csharp
Uri baseAddress = new Uri("http://localhost:8000/" + Guid.NewGuid().ToString());

// Create a ServiceHost for the CalculatorService type.
Expand All @@ -33,7 +33,7 @@ using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), base
## Client
In this project, note that the client hosts an <xref:System.ServiceModel.Discovery.AnnouncementService>. Furthermore, two delegates are registered with events. These events dictate what the client does when online and offline announcements are received.

```
```csharp
// Create an AnnouncementService instance
AnnouncementService announcementService = new AnnouncementService();

Expand All @@ -44,7 +44,7 @@ announcementService.OfflineAnnouncementReceived += OnOfflineEvent;

The `OnOnlineEvent` and `OnOfflineEvent` methods handle the hello and bye announcement messages respectively.

```
```csharp
static void OnOnlineEvent(object sender, AnnouncementEventArgs e)
{
Console.WriteLine();
Expand Down
6 changes: 3 additions & 3 deletions docs/framework/wcf/samples/asmx-client-with-a-wcf-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This sample demonstrates how to create a service using Windows Communication Fou

The service implements an `ICalculator` contract as defined in the following code.

```
```csharp
[ServiceContract(Namespace="http://Microsoft.ServiceModel.Samples"), XmlSerializerFormat]
public interface ICalculator
{
Expand Down Expand Up @@ -77,7 +77,7 @@ wsdl /n:Microsoft.ServiceModel.Samples /o:generatedClient.cs /urlkey:CalculatorS

The client implementation constructs an instance of the typed proxy to begin communicating with the service.

```
```csharp
// Create a client to the CalculatorService.
using (CalculatorService client = new CalculatorService())
{
Expand Down Expand Up @@ -114,7 +114,7 @@ Console.ReadLine();

When you run the sample, the operation requests and responses are displayed in the client console window. Press ENTER in the client window to shut down the client.

```
```console
Add(100,15.99) = 115.99
Subtract(145,76.54) = 68.46
Multiply(9,81.25) = 731.25
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ This sample demonstrates how to use the [\<serviceAuthorization>](../../../../do

The <xref:System.Security.Permissions.PrincipalPermissionAttribute> is applied to each operation to require the caller to be part of the Windows administrators group, as shown in the following sample code.

```
```csharp
[PrincipalPermission(SecurityAction.Demand,
Role = "Builtin\\Administrators")]
public double Add(double n1, double n2)
Expand Down
26 changes: 15 additions & 11 deletions docs/framework/wcf/samples/basic-data-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This sample demonstrates how to implement a data contract. Data contracts allow

The service contract for this service uses complex numbers, as shown in the following sample code.

```
```csharp
// Define a service contract.
[ServiceContract(Namespace="http://Microsoft.ServiceModel.Samples")]
public interface ICalculator
Expand All @@ -33,7 +33,7 @@ public interface ICalculator

The <xref:System.Runtime.Serialization.DataContractAttribute> and <xref:System.Runtime.Serialization.DataMemberAttribute> attributes have been applied to the definition of the `ComplexNumber` class to indicate which fields of the class can be passed over the wire between the client and the service, as shown in the following sample code.

```
```csharp
[DataContract(Namespace="http://Microsoft.ServiceModel.Samples")]
public class ComplexNumber
{
Expand All @@ -52,7 +52,7 @@ public class ComplexNumber

The service implementation calculates and returns the appropriate result, accepting and returning numbers of the `ComplexNumber` type.

```
```csharp
// This is the service class that implements the service contract.
public class CalculatorService : ICalculator
{
Expand Down Expand Up @@ -91,16 +91,20 @@ public class CalculatorService : ICalculator

The client implementation also uses complex numbers. Both the service contract and the data contract are defined in the source file generatedClient.cs, which is generated by the [ServiceModel Metadata Utility Tool (Svcutil.exe)](../../../../docs/framework/wcf/servicemodel-metadata-utility-tool-svcutil-exe.md) from service metadata.

```
```csharp
// Create a client.
DataContractCalculatorClient client = new DataContractCalculatorClient();
// Call the Add service operation.
ComplexNumber value1 = new ComplexNumber();
value1.Real = 1;
value1.Imaginary = 2;
ComplexNumber value2 = new ComplexNumber();
value2.Real = 3;
value2.Imaginary = 4;
ComplexNumber value1 = new ComplexNumber()
{
Real = 1,
Imaginary = 2
};
ComplexNumber value2 = new ComplexNumber()
{
Real = 3,
Imaginary = 4
};
ComplexNumber result = proxy.Add(value1, value2);
Console.WriteLine("Add({0} + {1}i, {2} + {3}i) = {4} + {5}i",
value1.Real, value1.Imaginary, value2.Real, value2.Imaginary,
Expand All @@ -111,7 +115,7 @@ Console.WriteLine("Add({0} + {1}i, {2} + {3}i) = {4} + {5}i",

When you run the sample, the requests and responses of the operation are displayed in the client console window. Press ENTER in the client window to shut down the client.

```
```console
Add(1 + 2i, 3 + 4i) = 4 + 6i
Subtract(1 + 2i, 3 + 4i) = -2 + -2i
Multiply(2 + 3i, 4 + 7i) = -13 + 26i
Expand Down
2 changes: 1 addition & 1 deletion docs/framework/wcf/samples/basic-sample.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This sample shows how to make a service discoverable and how to search for and c
## Service
This is a simple calculator service implementation. The discovery related code can be found in `Main` where a <xref:System.ServiceModel.Discovery.ServiceDiscoveryBehavior> is added to the service host and a <xref:System.ServiceModel.Discovery.UdpDiscoveryEndpoint> is added as shown in the following code.

```
```csharp
using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress))
{
serviceHost.AddServiceEndpoint(typeof(ICalculatorService), new
Expand Down
2 changes: 1 addition & 1 deletion docs/framework/wcf/samples/concurrency.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The Concurrency sample demonstrates using the <xref:System.ServiceModel.ServiceB

The service class specifies concurrency behavior with the `[ServiceBehavior(ConcurrencyMode=<setting>)]` attribute as shown in the code sample that follows. By changing which lines are commented out, you can experiment with the `Single` and `Multiple` concurrency modes. Remember to rebuild the service after changing the concurrency mode.

```
```csharp
// Single allows a single message to be processed sequentially by each service instance.
//[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single, InstanceContextMode = InstanceContextMode.Single)]

Expand Down
6 changes: 3 additions & 3 deletions docs/framework/wcf/samples/concurrencymode-reentrant.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This sample demonstrates the necessity and implications of using ConcurrencyMode

The contract defined is a duplex contract with the `Ping` method being implemented by the service and the callback method `Pong` being implemented by the client. A client invokes the server's `Ping` method with a tick count thereby initiating the call. The service checks whether the tick count is not equal to 0 and then invokes the callbacks `Pong` method while decrementing the tick count. This is done by the following code in the sample.

```
```csharp
public void Ping(int ticks)
{
Console.WriteLine("Ping: Ticks = " + ticks);
Expand All @@ -22,7 +22,7 @@ public void Ping(int ticks)

The callback's `Pong` implementation has the same logic as the `Ping` implementation. That is, it checks whether the tick count is not zero and then invokes the `Ping` method on the callback channel (in this case, it is the channel that was used to send the original `Ping` message) with the tick count decremented by 1. The moment the tick count reaches 0, the method returns thereby unwrapping all the replies back to the first call made by the client that initiated the call. This is shown in the callback implementation.

```
```csharp
public void Pong(int ticks)
{
Console.WriteLine("Pong: Ticks = " + ticks);
Expand All @@ -49,7 +49,7 @@ public void Pong(int ticks)
## Demonstrates
To run the sample, build the client and server projects. Then open two command windows and change the directories to the \<sample>\CS\Service\bin\debug and \<sample>\CS\Client\bin\debug directories. Then start the service by typing `service.exe` and then invoke the Client.exe with the initial value of ticks passed as an input argument. A sample output for 10 ticks is shown.

```
```console
Prompt>Service.exe
ServiceHost Started. Press Enter to terminate service.
Ping: Ticks = 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This sample covers the usage of the <xref:System.ServiceModel.Configuration.Conf

The following code adds a custom configuration file to a client application.

```
```csharp
ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = "Test.config";
Configuration newConfiguration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
Expand Down
2 changes: 1 addition & 1 deletion docs/framework/wcf/samples/datacontractresolver.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void deserialize(Type type)

The following code example is a class deriving from <xref:System.Runtime.Serialization.DataContractResolver>.

```
```csharp
class MyDataContractResolver : DataContractResolver
{
private Dictionary<string, XmlDictionaryString> dictionary = new Dictionary<string, XmlDictionaryString>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This sample demonstrates how the use of <xref:System.Runtime.Serialization.DataC

The following code example shows the implementation of a custom <xref:System.Runtime.Serialization.DataContractResolver> named `MyDataContractResolver` that is added to the <xref:System.Runtime.Serialization.DataContractSerializer> in the DCSwithDCR project.

```
```csharp
class MyDataContractResolver : DataContractResolver
{
private XmlDictionary dictionary = new XmlDictionary();
Expand Down
12 changes: 6 additions & 6 deletions docs/framework/wcf/samples/datacontractserializer-sample.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The DataContractSerializer sample demonstrates the <xref:System.Runtime.Serializ

The data contract for `Record` is shown in the following sample code.

```
```csharp
[DataContract(Namespace="http://Microsoft.ServiceModel.Samples")]
internal class Record
{
Expand Down Expand Up @@ -68,14 +68,14 @@ internal class Record

The sample code creates a `Record` object named `record1` then displays the object.

```
```csharp
Record record1 = new Record(1, 2, "+", 3);
Console.WriteLine("Original record: {0}", record1.ToString());
```

The sample then uses the <xref:System.Runtime.Serialization.DataContractSerializer> to serialize `record1` into a memory stream.

```
```csharp
MemoryStream stream1 = new MemoryStream();

//Serialize the Record object to a memory stream using DataContractSerializer.
Expand All @@ -85,7 +85,7 @@ serializer.WriteObject(stream1, record1);

Next, the sample uses the <xref:System.Runtime.Serialization.DataContractSerializer> to deserialize the memory stream back into a new `Record` object and displays it.

```
```csharp
stream1.Position = 0;

//Deserialize the Record object back into a new record object.
Expand All @@ -96,7 +96,7 @@ Console.WriteLine("Deserialized record: {0}", record2.ToString());

By default, the `DataContractSerializer` encodes objects into a stream using a textual representation of XML. However, you can influence the encoding of the XML by passing in a different writer. The sample creates a binary writer by calling <xref:System.Xml.XmlDictionaryWriter.CreateBinaryWriter%2A>. It then passes the writer and the record object to the serializer when it calls <xref:System.Runtime.Serialization.DataContractSerializer.WriteObjectContent%2A>. Finally, the sample flushes the writer and reports on the length of the streams.

```
```csharp
MemoryStream stream2 = new MemoryStream();

XmlDictionaryWriter binaryDictionaryWriter = XmlDictionaryWriter.CreateBinaryWriter(stream2);
Expand All @@ -110,7 +110,7 @@ Console.WriteLine("Binary Stream is {0} bytes long", stream2.Length);

When you run the sample, the original record and the deserialized record are displayed, followed by the comparison between the length of the text encoding and the binary encoding. Press ENTER in the client window to shut down the client.

```
```console
Original record: Record: 1 + 2 = 3
Deserialized record: Record: 1 + 2 = 3
Text Stream is 233 bytes long
Expand Down
22 changes: 12 additions & 10 deletions docs/framework/wcf/samples/default-message-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The Default Message Contract sample demonstrates a service where a custom user-d

In the service, a single service operation is defined that accepts and returns custom messages of type `MyMessage`. Although in this sample the request and response messages are of the same type, they could of course be different message contracts if necessary.

```
```csharp
[ServiceContract(Namespace="http://Microsoft.ServiceModel.Samples")]
public interface ICalculator
{
Expand All @@ -27,7 +27,7 @@ public interface ICalculator

The custom message `MyMessage` is defined in a class annotated with <xref:System.ServiceModel.MessageContractAttribute>, <xref:System.ServiceModel.MessageHeaderAttribute> and <xref:System.ServiceModel.MessageBodyMemberAttribute> attributes. Only the third constructor is used in this sample. Using message contracts allows you to exercise full control over the SOAP message. In this sample, the <xref:System.ServiceModel.MessageHeaderAttribute> attribute is used to put `Operation` in a SOAP header. The operands `N1`, `N2` and the `Result` appear within the SOAP body because they have the <xref:System.ServiceModel.MessageBodyMemberAttribute> attribute applied.

```
```csharp
[MessageContract]
public class MyMessage
{
Expand Down Expand Up @@ -93,7 +93,7 @@ public class MyMessage

The implementation class contains the code for the `Calculate` service operation. The `CalculateService` class obtains the operands and operator from the request message and creates a response message that contains the result of the requested calculation, as shown in the following sample code.

```
```csharp
// Service class which implements the service contract.
public class CalculatorService : ICalculator
{
Expand Down Expand Up @@ -127,29 +127,31 @@ public class CalculatorService : ICalculator

The generated client code for the client was created with the [ServiceModel Metadata Utility Tool (Svcutil.exe)](../../../../docs/framework/wcf/servicemodel-metadata-utility-tool-svcutil-exe.md) tool. The tool automatically creates message contract types in the generated client code if necessary. The `/messageContract` command option may be specified to force the generation of message contracts.

```
```console
svcutil.exe /n:"http://Microsoft.ServiceModel.Samples,Microsoft.ServiceModel.Samples" /o:client\generatedClient.cs http://localhost/servicemodelsamples/service.svc/mex
```

The following sample code demonstrates the client using the `MyMessage` message.

```
```csharp
// Create a client with given client endpoint configuration
CalculatorClient client = new CalculatorClient();

// Perform addition using a typed message.

MyMessage request = new MyMessage();
request.N1 = 100D;
request.N2 = 15.99D;
request.Operation = "+";
MyMessage request = new MyMessage()
{
N1 = 100D,
N2 = 15.99D,
Operation = "+"
};
MyMessage response = ((ICalculator)client).Calculate(request);
Console.WriteLine("Add({0},{1}) = {2}", request.N1, request.N2, response.Result);
```

When you run the sample, the calculations are displayed in the client console window. Press ENTER in the client window to shut down the client.

```
```console
Add(100,15.99) = 115.99
Subtract(145,76.54) = 68.46
Multiply(9,81.25) = 731.25
Expand Down
4 changes: 2 additions & 2 deletions docs/framework/wcf/samples/default-service-behavior.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This sample demonstrates how service behavior settings can be configured. The sa

The service class specifies behaviors with the <xref:System.ServiceModel.ServiceBehaviorAttribute> and the <xref:System.ServiceModel.OperationBehaviorAttribute> as shown in the following code sample. All values specified are the defaults.

```
```csharp
[ServiceBehavior(
AutomaticSessionShutdown=true,
ConcurrencyMode=ConcurrencyMode.Single,
Expand Down Expand Up @@ -62,7 +62,7 @@ public class CalculatorService : ICalculator

When you run the sample, the operation requests and responses are displayed in the client console window. The delay between the calls is the result of the calls to `System.Threading.Thread.Sleep()` made in the service operations. The rest of the behavior samples explain these behaviors in more detail. Press ENTER in the client window to shut down the client.

```
```console
Add(100,15.99) = 115.99
Subtract(145,76.54) = 68.46
Multiply(9,81.25) = 731.25
Expand Down
Loading