Skip to content

Commit 5bb73a1

Browse files
johnmwrightmairaw
authored andcommitted
apply code highlighting (#4991)
* (WFC:Basic:Client) apply csharp syntax highlighting to code samples * (WFC:Basic:AJAX) apply syntax highlighting to code samples Plus mark a handful of inline code blocks that weren't previously inline code blocks * (WFC:Basic:Binding) apply syntax highlighting to code samples * Update ajax-service-with-json-and-xml-sample.md * Update ajax-service-without-configuration.md * Update basic-ajax-service.md * Update jsonp.md
1 parent 87dc518 commit 5bb73a1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+470
-475
lines changed

docs/framework/wcf/samples/address-headers.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ The Address Headers sample demonstrates how clients can pass reference parameter
3232
## Client
3333
For the client to send a reference parameter, it must add an `AddressHeader` to the `EndpointAddress` of the `ServiceEndpoint`. Because the `EndpointAddress` class is immutable, modification of an endpoint address must be done using the `EndpointAddressBuilder` class. The following code initializes the client to send a reference parameter as part of its message.
3434

35-
```
35+
```csharp
3636
HelloClient client = new HelloClient();
3737
EndpointAddressBuilder builder =
3838
new EndpointAddressBuilder(client.Endpoint.Address);
@@ -51,23 +51,21 @@ client.Endpoint.Address = builder.ToEndpointAddress();
5151
## Server
5252
The implementation of the service operation `Hello()` uses the current `OperationContext` to inspect the values of the headers on the incoming message.
5353

54-
```
54+
```csharp
5555
string id = null;
5656
// look at headers on incoming message
5757
for (int i = 0;
5858
i < OperationContext.Current.IncomingMessageHeaders.Count;
5959
++i)
6060
{
61-
MessageHeaderInfo h =
62-
OperationContext.Current.IncomingMessageHeaders[i];
61+
MessageHeaderInfo h = OperationContext.Current.IncomingMessageHeaders[i];
6362
// for any reference parameters with the correct name & namespace
6463
if (h.IsReferenceParameter &&
6564
h.Name == IDName &&
6665
h.Namespace == IDNamespace)
6766
{
6867
// read the value of that header
69-
XmlReader xr =
70-
OperationContext.Current.IncomingMessageHeaders.GetReaderAtHeader(i);
68+
XmlReader xr = OperationContext.Current.IncomingMessageHeaders.GetReaderAtHeader(i);
7169
id = xr.ReadElementContentAsString();
7270
}
7371
}

docs/framework/wcf/samples/ajax-service-using-complex-types-sample.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,37 @@ This sample demonstrates how to use [!INCLUDE[indigo1](../../../../includes/indi
2626
> The setup procedure and build instructions for this sample are located at the end of this topic.
2727
2828
The service in the following sample is a [!INCLUDE[indigo2](../../../../includes/indigo2-md.md)] service with no AJAX-specific code. Because the <xref:System.ServiceModel.Web.WebGetAttribute> attribute is not applied, the default HTTP verb ("POST") is used. The service has one operation, `DoMath`, which returns a complex type named `MathResult`. The complex type is a standard data contract type, which also contains no AJAX-specific code.
29-
30-
```
29+
30+
```csharp
3131
[DataContract]
32-
public class MathResult
33-
{
34-
[DataMember]
35-
public double sum;
36-
[DataMember]
37-
public double difference;
38-
[DataMember]
39-
public double product;
40-
[DataMember]
41-
public double quotient;
42-
}
43-
```
44-
32+
public class MathResult
33+
{
34+
[DataMember]
35+
public double sum;
36+
[DataMember]
37+
public double difference;
38+
[DataMember]
39+
public double product;
40+
[DataMember]
41+
public double quotient;
42+
}
43+
```
44+
4545
Create an AJAX endpoint on the service by using the <xref:System.ServiceModel.Activation.WebScriptServiceHostFactory>, just as in the Basic AJAX Service sample.
4646

4747
The client Web page ComplexTypeClientPage.aspx contains ASP.NET and JavaScript code to invoke the service when the user clicks the **Perform calculation** button on the page. The code to invoke the service constructs a JSON body and sends it using HTTP POST, similar to the [AJAX Service Using HTTP POST](../../../../docs/framework/wcf/samples/ajax-service-using-http-post.md) sample.
4848

4949
After the service call succeeds, you can access the individual data members (`sum`, `difference`, `product` and `quotient`) on the resulting JavaScript object.
50-
51-
```
50+
51+
```javascript
5252
function onSuccess(mathResult){
5353
document.getElementById("sum").value = mathResult.sum;
5454
document.getElementById("difference").value = mathResult.difference;
5555
document.getElementById("product").value = mathResult.product;
5656
document.getElementById("quotient").value = mathResult.quotient;
5757
}
58-
```
59-
58+
```
59+
6060
### To set up, build, and run the sample
6161

6262
1. Ensure that you have performed the [One-Time Setup Procedure for the Windows Communication Foundation Samples](../../../../docs/framework/wcf/samples/one-time-setup-procedure-for-the-wcf-samples.md).

docs/framework/wcf/samples/ajax-service-using-http-post.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,17 @@ This sample demonstrates how to use [!INCLUDE[indigo1](../../../../includes/indi
2828
The service in the following sample is a [!INCLUDE[indigo2](../../../../includes/indigo2-md.md)] service with no AJAX-specific code.
2929

3030
If the <xref:System.ServiceModel.Web.WebInvokeAttribute> attribute is applied on an operation, or the <xref:System.ServiceModel.Web.WebGetAttribute> attribute is not applied, the default HTTP verb ("POST") is used. POST requests are harder to construct than GET requests, but they are not cached; use POST requests for all operations where caching is not appropriate.
31-
32-
```
31+
32+
```csharp
3333
[ServiceContract(Namespace = "PostAjaxService")]
34-
public interface ICalculator
35-
{ [WebInvoke]
36-
double Add(double n1, double n2);
37-
//Other operations omitted…
38-
}
39-
```
40-
34+
public interface ICalculator
35+
{
36+
[WebInvoke]
37+
double Add(double n1, double n2);
38+
//Other operations omitted…
39+
}
40+
```
41+
4142
Create an AJAX endpoint on the service by using the <xref:System.ServiceModel.Activation.WebScriptServiceHostFactory>, just as in the Basic AJAX Service sample.
4243

4344
Unlike GET requests, you cannot invoke POST services from the browser. For example, navigating to http://localhost/ServiceModelSamples/service.svc/Add?n1=100&n2=200 results in an error, because the POST service expects the `n1` and `n2` parameters to be sent in the message body—in the JSON format—and not in the URL.

docs/framework/wcf/samples/ajax-service-with-json-and-xml-sample.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ This sample demonstrates how to use [!INCLUDE[indigo1](../../../../includes/indi
2929
3030
To enable the use of non-ASP.NET AJAX clients, use <xref:System.ServiceModel.Activation.WebServiceHostFactory> (not <xref:System.ServiceModel.Activation.WebScriptServiceHostFactory>) in the .svc file. <xref:System.ServiceModel.Activation.WebServiceHostFactory> adds a <xref:System.ServiceModel.Description.WebHttpEndpoint> standard endpoint to the service. The endpoint is configured at an empty address relative to the .svc file; this means that the address of the service is http://localhost/ServiceModelSamples/service.svc, with no additional suffixes other than the operation name.
3131

32-
```html
32+
```svc
3333
<%@ServiceHost language="c#" Debug="true" Service="Microsoft.Samples.XmlAjaxService.CalculatorService" Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>
3434
```
3535

@@ -49,28 +49,28 @@ This sample demonstrates how to use [!INCLUDE[indigo1](../../../../includes/indi
4949
The default data format for <xref:System.ServiceModel.Description.WebHttpEndpoint> is XML, while the default data format for <xref:System.ServiceModel.Description.WebScriptEndpoint> is JSON. For more information, see [Creating WCF AJAX Services without ASP.NET](../../../../docs/framework/wcf/feature-details/creating-wcf-ajax-services-without-aspnet.md).
5050

5151
The service in the following sample is a standard [!INCLUDE[indigo2](../../../../includes/indigo2-md.md)] service with two operations. Both operations require the <xref:System.ServiceModel.Web.WebMessageBodyStyle.Wrapped> body style on the <xref:System.ServiceModel.Web.WebGetAttribute> or <xref:System.ServiceModel.Web.WebInvokeAttribute> attributes, which is specific to the `webHttp` behavior and has no bearing on the JSON/XML data format switch.
52-
53-
```
52+
53+
```csharp
5454
[OperationContract]
5555
[WebInvoke(ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped)]
5656
MathResult DoMathXml(double n1, double n2);
57-
```
58-
57+
```
58+
5959
The response format for the operation is specified as XML, which is the default setting for the [\<webHttp>](../../../../docs/framework/configure-apps/file-schema/wcf/webhttp.md) behavior. However, it is good practice explicitly specify the response format.
6060

6161
The other operation uses the `WebInvokeAttribute` attribute and explicitly specifies JSON instead of XML for the response.
62-
63-
```
62+
63+
```csharp
6464
[OperationContract]
6565
[WebInvoke(ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
6666
MathResult DoMathJson(double n1, double n2);
67-
```
68-
67+
```
68+
6969
Note that in both cases the operations return a complex type, `MathResult`, which is a standard [!INCLUDE[indigo2](../../../../includes/indigo2-md.md)] data contract type.
7070

7171
The client Web page XmlAjaxClientPage.htm contains JavaScript code that invokes one of the preceding two operations when the user clicks the **Perform calculation (return JSON)** or **Perform calculation (return XML)** buttons on the page. The code to invoke the service constructs a JSON body and sends it using HTTP POST. The request is created manually in JavaScript, unlike the [Basic AJAX Service](../../../../docs/framework/wcf/samples/basic-ajax-service.md) sample and the other samples using ASP.NET AJAX.
72-
73-
```
72+
73+
```csharp
7474
// Create HTTP request
7575
var xmlHttp;
7676
// Request instantiation code omitted…
@@ -89,19 +89,19 @@ body = body + document.getElementById("num2").value + '}';
8989
xmlHttp.open("POST", url, true);
9090
xmlHttp.setRequestHeader("Content-type", "application/json");
9191
xmlHttp.send(body);
92-
```
93-
92+
```
93+
9494
When the service responds, the response is displayed without any further processing in a textbox on the page. This is implemented for demonstration purposes to allow you to directly observe the XML and JSON data formats used.
95-
96-
```
95+
96+
```javascript
9797
// Create result handler
9898
xmlHttp.onreadystatechange=function(){
9999
if(xmlHttp.readyState == 4){
100100
document.getElementById("result").value = xmlHttp.responseText;
101101
}
102102
}
103-
```
104-
103+
```
104+
105105
> [!IMPORTANT]
106106
> The samples may already be installed on your machine. Check for the following (default) directory before continuing.
107107
>

docs/framework/wcf/samples/ajax-service-without-configuration.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ This sample demonstrates how to use [!INCLUDE[indigo1](../../../../includes/indi
2626
> The setup procedure and build instructions for this sample are located at the end of this topic.
2727
2828
This sample builds upon the AJAX Service Using HTTP POST. As described in the [Basic AJAX Service](../../../../docs/framework/wcf/samples/basic-ajax-service.md) sample, <xref:System.ServiceModel.Activation.WebScriptServiceHostFactory> is used to host the service.
29-
30-
```
29+
30+
```svc
3131
<%ServiceHost
3232
language=c#
3333
Debug="true"
3434
Service="Microsoft.Ajax.Samples.CalculatorService
3535
Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory"
3636
%>
37-
```
38-
39-
<xref:System.ServiceModel.Activation.WebScriptServiceHostFactory> automatically adds a <xref:System.ServiceModel.Description.WebScriptEndpoint> to the service. If no configuration changes need to be made to the endpoint, the \<system.ServiceModel> section can be completely removed from the Web.config file for the service. The Web.config file contains some ASP.NET settings, which are used by ConfigFreeClientPage.aspx. If that were not the case, the entire Web.config file could be removed.
37+
```
38+
39+
<xref:System.ServiceModel.Activation.WebScriptServiceHostFactory> automatically adds a <xref:System.ServiceModel.Description.WebScriptEndpoint> to the service. If no configuration changes need to be made to the endpoint, the `<system.ServiceModel>` section can be completely removed from the Web.config file for the service. The Web.config file contains some ASP.NET settings, which are used by ConfigFreeClientPage.aspx. If that were not the case, the entire Web.config file could be removed.
4040

4141
> [!IMPORTANT]
4242
> The samples may already be installed on your computer. Check for the following (default) directory before continuing.

docs/framework/wcf/samples/avoiding-problems-with-the-using-statement.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ This sample demonstrates how you should not use the C# "using" statement to auto
2929

3030
The first problem, illustrated in the `DemonstrateProblemUsingCanThrow` method, is that the closing brace throws an exception and the code after the closing brace does not execute:
3131

32-
```
32+
```csharp
3333
using (CalculatorClient client = new CalculatorClient())
3434
{
3535
...
@@ -41,7 +41,7 @@ Console.WriteLine("Hope this code wasn't important, because it might not happen.
4141

4242
The second problem, illustrated in the `DemonstrateProblemUsingCanThrowAndMask` method, is another implication of the closing brace throwing an exception:
4343

44-
```
44+
```csharp
4545
using (CalculatorClient client = new CalculatorClient())
4646
{
4747
...
@@ -54,7 +54,7 @@ using (CalculatorClient client = new CalculatorClient())
5454

5555
Finally, the sample demonstrates how to clean up correctly when exceptions occur in `DemonstrateCleanupWithExceptions`. This uses a try/catch block to report errors and call `Abort`. See the [Expected Exceptions](../../../../docs/framework/wcf/samples/expected-exceptions.md) sample for more details about catching exceptions from client calls.
5656

57-
```
57+
```csharp
5858
try
5959
{
6060
...

docs/framework/wcf/samples/basic-ajax-service.md

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,23 @@ This sample demonstrates how to use [!INCLUDE[indigo1](../../../../includes/indi
2626
> The set-up procedure and build instructions for this sample are located at the end of this topic.
2727
2828
In the following code, the <xref:System.ServiceModel.Web.WebGetAttribute> attribute is applied to the `Add` operation to ensure that the service responds to HTTP GET requests. The code uses GET for simplicity (you can construct an HTTP GET request from any Web browser). You can also use GET to enable caching. HTTP POST is the default in the absence of the `WebGetAttribute` attribute.
29-
30-
```
31-
[ServiceContract(Namespace = "SimpleAjaxService")]
32-
public interface ICalculator
33-
{
34-
35-
[WebGet]
36-
double Add(double n1, double n2);
37-
//Other operations omitted…
38-
}
39-
```
40-
29+
30+
```csharp
31+
[ServiceContract(Namespace = "SimpleAjaxService")]
32+
public interface ICalculator
33+
{
34+
[WebGet]
35+
double Add(double n1, double n2);
36+
//Other operations omitted…
37+
}
38+
```
39+
4140
The sample .svc file uses <xref:System.ServiceModel.Activation.WebScriptServiceHostFactory>, which adds a <xref:System.ServiceModel.Description.WebScriptEndpoint> standard endpoint to the service. The endpoint is configured at an empty address relative to the .svc file. This means that the address of the service is http://localhost/ServiceModelSamples/service.svc, with no additional suffixes other than the operation name.
42-
43-
```
44-
<%@ServiceHost language="C#" Debug="true" Service="Microsoft.Samples.SimpleAjaxService.CalculatorService" Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory" %>
45-
```
46-
41+
42+
```svc
43+
<%@ServiceHost language="C#" Debug="true" Service="Microsoft.Samples.SimpleAjaxService.CalculatorService" Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory" %>
44+
```
45+
4746
The <xref:System.ServiceModel.Description.WebScriptEndpoint> is pre-configured to make the service accessible from an ASP.NET AJAX client page. The following section in Web.config can be used to make additional configuration changes to the endpoint. It can be removed if no extra changes are required.
4847

4948
```xml
@@ -60,33 +59,33 @@ public interface ICalculator
6059
The <xref:System.ServiceModel.Description.WebScriptEndpoint> sets the default data format for the service to JSON instead of XML. To invoke the service, navigate to http://localhost/ServiceModelSamples/service.svc/Add?n1=100&n2=200 after completing the set up and build steps shown later in this topic. This testing functionality is enabled by the use of a HTTP GET request.
6160

6261
The client Web page SimpleAjaxClientPage.aspx contains ASP.NET code to invoke the service whenever the user clicks one of the operation buttons on the page. The `ScriptManager` control is used to make a proxy to the service accessible through JavaScript.
63-
64-
```
62+
63+
```aspx-csharp
6564
<asp:ScriptManager ID="ScriptManager" runat="server">
6665
<Services>
6766
<asp:ServiceReference Path="service.svc" />
6867
</Services>
6968
</asp:ScriptManager>
70-
```
71-
69+
```
70+
7271
The local proxy is instantiated and operations are invoked using the following JavaScript code.
73-
74-
```
72+
73+
```javascript
7574
// Code for extracting arguments n1 and n2 omitted…
7675
// Instantiate a service proxy
7776
var proxy = new SimpleAjaxService.ICalculator();
7877
// Code for selecting operation omitted…
7978
proxy.Add(parseFloat(n1), parseFloat(n2), onSuccess, onFail, null);
80-
```
81-
79+
```
80+
8281
If the service call succeeds, the code invokes the `onSuccess` handler and the result of the operation is displayed in a text box.
83-
84-
```
82+
83+
```javascript
8584
function onSuccess(mathResult){
8685
document.getElementById("result").value = mathResult;
87-
}
88-
```
89-
86+
}
87+
```
88+
9089
> [!IMPORTANT]
9190
> The samples may already be installed on your machine. Check for the following (default) directory before continuing.
9291
>

docs/framework/wcf/samples/basicbinding-with-transport-security.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,13 @@ This sample demonstrates the use of SSL transport security with the basic bindin
6363
```
6464

6565
Because the certificate used in this sample is a test certificate created with Makecert.exe, a security alert appears when you try to access an HTTPS: address in your browser, such as https://localhost/servicemodelsamples/service.svc. To allow the [!INCLUDE[indigo1](../../../../includes/indigo1-md.md)] client to work with a test certificate, some additional code is added to the client to suppress the security alert. This code, and the accompanying class, is not necessary when using real certificates.
66-
67-
```
66+
67+
```csharp
6868
// This code is required only for test certificates such as those
6969
// created by Makecert.exe.
70-
PermissiveCertificatePolicy.Enact(
71-
"CN=ServiceModelSamples-HTTPS-Server");
72-
```
73-
70+
PermissiveCertificatePolicy.Enact("CN=ServiceModelSamples-HTTPS-Server");
71+
```
72+
7473
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.
7574

7675
```

docs/framework/wcf/samples/channel-factory.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ This sample demonstrates how a client application can create a channel with the
2525
2626
This sample uses the <xref:System.ServiceModel.ChannelFactory%601> class to create a channel to a service endpoint. Typically, to create a channel to a service endpoint you generate a client type with the [ServiceModel Metadata Utility Tool (Svcutil.exe)](../../../../docs/framework/wcf/servicemodel-metadata-utility-tool-svcutil-exe.md) and create an instance of the generated type. You can also create a channel by using the <xref:System.ServiceModel.ChannelFactory%601> class, as demonstrated in this sample. The service created by the following sample code is identical to the service in the [Getting Started](../../../../docs/framework/wcf/samples/getting-started-sample.md).
2727

28-
```
28+
```csharp
2929
EndpointAddress address = new EndpointAddress("http://localhost/servicemodelsamples/service.svc");
3030
WSHttpBinding binding = new WSHttpBinding();
3131
ChannelFactory<ICalculator> factory = new
@@ -38,7 +38,7 @@ ICalculator channel = factory.CreateChannel();
3838

3939
Once the channel is created, service operations can be invoked just as with a generated client.
4040

41-
```
41+
```csharp
4242
// Call the Add service operation.
4343
double value1 = 100.00D;
4444
double value2 = 15.99D;
@@ -48,7 +48,7 @@ Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);
4848

4949
To close the channel, it must first be cast to an <xref:System.ServiceModel.IClientChannel> interface. This is because the channel as generated is declared in the client application using the `ICalculator` interface, which has methods like `Add` and `Subtract` but not `Close`. The `Close` method originates on the <xref:System.ServiceModel.ICommunicationObject> interface.
5050

51-
```
51+
```csharp
5252
// Close the channel.
5353
((IClientChannel)client).Close();
5454
```
@@ -76,7 +76,7 @@ Press <ENTER> to terminate client.
7676

7777
1. Replace "localhost" in the following code with the fully-qualified name of the machine that is running the service.
7878

79-
```
79+
```csharp
8080
EndpointAddress address = new EndpointAddress("http://localhost/servicemodelsamples/service.svc");
8181
```
8282

0 commit comments

Comments
 (0)