Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/framework/data/adonet/asynchronous-programming.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class A {

SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
Console.WriteLine(String.Format("{0}", reader[0]));
Console.WriteLine(reader[0]);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ Imports System.Data.SqlClient

Catch ex As Exception
isExecuting = False
DisplayStatus( _
String.Format("Ready (last error: {0})", _
ex.Message))
DisplayStatus($"Ready (last error: {ex.Message})")
If connection IsNot Nothing Then
connection.Close()
End If
Expand Down Expand Up @@ -177,7 +175,7 @@ Imports System.Data.SqlClient
' invoke it, like this:
Me.Invoke(New _
DisplayInfoDelegate(AddressOf DisplayStatus), _
String.Format("Ready(last error: {0}", ex.Message))
$"Ready (last error: {ex.Message}")
Finally
isExecuting = False
If connection IsNot Nothing Then
Expand Down Expand Up @@ -295,8 +293,7 @@ private void button1_Click(object sender, System.EventArgs e)
catch (Exception ex)
{
isExecuting = false;
DisplayStatus(
string.Format("Ready (last error: {0})", ex.Message));
DisplayStatus($"Ready (last error: {ex.Message})");
if (connection != null)
{
connection.Close();
Expand Down Expand Up @@ -352,7 +349,7 @@ private void HandleCallback(IAsyncResult result)
// You can create the delegate instance as you
// invoke it, like this:
this.Invoke(new DisplayInfoDelegate(DisplayStatus),
String.Format("Ready(last error: {0}", ex.Message));
$"Ready (last error: {ex.Message}");
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,9 @@ class Program {

// Build the query string
String primaryCols = String.Join(",", primaryColumns.Select(col => col.ColumnName));
String resetCols = String.Join(",", resetColumns.Select(col => "Max(" + col.ColumnName + ") as " + col.ColumnName));
String resetCols = String.Join(",", resetColumns.Select(col => $"Max({col.ColumnName}) as {col.ColumnName}"));

String selectString = String.Format("Select {0},{1} from Course Group by {0}", primaryCols, resetCols);
String selectString = $"Select {primaryCols},{resetCols} from Course Group by {primaryCols}");

SqlCommand selectCommand = new SqlCommand(selectString);

Expand Down
2 changes: 1 addition & 1 deletion docs/framework/wcf/configuring-wcf-services-in-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class Service1 : IService1

public string GetData(int value)
{
return string.Format("You entered: {0}", value);
return $"You entered: {value}";
}

public CompositeType GetDataUsingDataContract(CompositeType composite)
Expand Down
3 changes: 1 addition & 2 deletions docs/framework/wcf/diagnostics/wmi/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ Whoami /user
You can also access remote WMI instances programmatically by using classes provided by the <xref:System.Management> namespace. The following code sample demonstrates how to do this.

```csharp
String wcfNamespace = String.Format(@"\\{0}\Root\ServiceModel",
this.serviceMachineName);
String wcfNamespace = $@"\\{this.serviceMachineName}\Root\ServiceModel");

ConnectionOptions connection = new ConnectionOptions();
connection.Authentication = AuthenticationLevel.PacketPrivacy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Multicasting applications send small messages to a large number of recipients at
## Implementing a Multicast Application
To implement a multicast application, define a service contract and for each software component that needs to respond to the multicast messages, implement the service contract. For example, a stock ticker application might define a service contract:

```
```csharp
// Shared contracts between the client and the service
[ServiceContract]
interface IStockTicker
Expand Down Expand Up @@ -37,7 +37,7 @@ class StockInfo

Each application that wants to receive multicast messages must host a service that exposes this interface. For example, here is a code sample that illustrates how to receive multicast messages:

```
```csharp
// Service Address
string serviceAddress = "soap.udp://224.0.0.1:40000";
// Binding
Expand All @@ -57,7 +57,7 @@ Console.ReadLine();

In this type of a scenario it is the client that actually sends out multicast messages. Each service that is listening at the correct UDP address will receive the multicast messages. Here is an example of a client that sends out multicast messages:

```
```csharp
// Multicast Address
string serviceAddress = "soap.udp://224.0.0.1:40000";

Expand All @@ -76,7 +76,7 @@ while (true)
{
// This will continue to mulicast stock information
proxy.SendStockInfo(GetStockInfo());
Console.WriteLine(String.Format("sent stock info at {0}", DateTime.Now));
Console.WriteLine($"sent stock info at {DateTime.Now}");
// Wait for one second before sending another update
System.Threading.Thread.Sleep(new TimeSpan(0, 0, 1));
}
Expand All @@ -90,7 +90,7 @@ while (true)
### Two-way Multicast Messaging
While multicast messages are generally one-way, the UdpBinding does support request/reply message exchange. Messages sent using the UDP transport contain both a From and To address. Care must be taken when using the From address as it could be maliciously changed en-route. The address can be checked using the following code:

```
```csharp
if (address.AddressFamily == AddressFamily.InterNetwork)
{
// IPv4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This sample demonstrates various aspects of creating a transactional service and

1. Create a service contract and annotate the operations with the desired setting from the <xref:System.ServiceModel.TransactionFlowOption> enumeration to specify the incoming transaction requirements. Note that you can also place the <xref:System.ServiceModel.TransactionFlowAttribute> on the service class being implemented. This allows for a single implementation of an interface to use these transaction settings, instead of every implementation.

```
```csharp
[ServiceContract]
public interface ICalculator
{
Expand All @@ -27,7 +27,7 @@ This sample demonstrates various aspects of creating a transactional service and

2. Create an implementation class, and use the <xref:System.ServiceModel.ServiceBehaviorAttribute> to optionally specify a <xref:System.ServiceModel.ServiceBehaviorAttribute.TransactionIsolationLevel%2A> and a <xref:System.ServiceModel.ServiceBehaviorAttribute.TransactionTimeout%2A>. You should note that in many cases, the default <xref:System.ServiceModel.ServiceBehaviorAttribute.TransactionTimeout%2A> of 60 seconds and the default <xref:System.ServiceModel.ServiceBehaviorAttribute.TransactionIsolationLevel%2A> of `Unspecified` are appropriate. For each operation, you can use the <xref:System.ServiceModel.OperationBehaviorAttribute> attribute to specify whether work performed within the method should occur within the scope of a transaction scope according to the value of the <xref:System.ServiceModel.OperationBehaviorAttribute.TransactionScopeRequired%2A> attribute. In this case, the transaction used for the `Add` method is the same as the mandatory incoming transaction that is flowed from the client, and the transaction used for the `Subtract` method is either the same as the incoming transaction if one was flowed from the client, or a new implicitly and locally created transaction.

```
```csharp
[ServiceBehavior(
TransactionIsolationLevel = System.Transactions.IsolationLevel.Serializable,
TransactionTimeout = "00:00:45")]
Expand All @@ -37,15 +37,15 @@ This sample demonstrates various aspects of creating a transactional service and
public double Add(double n1, double n2)
{
// Perform transactional operation
RecordToLog(String.Format("Adding {0} to {1}", n1, n2));
RecordToLog($"Adding {n1} to {n2}");
return n1 + n2;
}

[OperationBehavior(TransactionScopeRequired = true)]
public double Subtract(double n1, double n2)
{
// Perform transactional operation
RecordToLog(String.Format("Subtracting {0} from {1}", n2, n1));
RecordToLog($"Subtracting {n2} from {n1}");
return n1 - n2;
}

Expand Down Expand Up @@ -122,7 +122,7 @@ This sample demonstrates various aspects of creating a transactional service and

1. By default, WCF operations automatically complete transactions if no unhandled exceptions are thrown. You can modify this behavior by using the <xref:System.ServiceModel.OperationBehaviorAttribute.TransactionAutoComplete%2A> property and the <xref:System.ServiceModel.OperationContext.SetTransactionComplete%2A> method. When an operation is required to occur within the same transaction as another operation (for example, a debit and credit operation), you can disable the autocomplete behavior by setting the <xref:System.ServiceModel.OperationBehaviorAttribute.TransactionAutoComplete%2A> property to `false` as shown in the following `Debit` operation example. The transaction the `Debit` operation uses is not completed until a method with the <xref:System.ServiceModel.OperationBehaviorAttribute.TransactionAutoComplete%2A> property set to `true` is called, as shown in the operation `Credit1`, or when the <xref:System.ServiceModel.OperationContext.SetTransactionComplete%2A> method is called to explicitly mark the transaction as complete, as shown in the operation `Credit2`. Note that the two credit operations are shown for illustration purposes, and that a single credit operation would be more typical.

```
```csharp
[ServiceBehavior]
public class CalculatorService : IAccount
{
Expand Down Expand Up @@ -158,7 +158,7 @@ This sample demonstrates various aspects of creating a transactional service and

2. For the purposes of transaction correlation, setting the <xref:System.ServiceModel.OperationBehaviorAttribute.TransactionAutoComplete%2A> property to `false` requires the use of a sessionful binding. This requirement is specified with the `SessionMode` property on the <xref:System.ServiceModel.ServiceContractAttribute>.

```
```csharp
[ServiceContract(SessionMode = SessionMode.Required)]
public interface IAccount
{
Expand All @@ -178,7 +178,7 @@ This sample demonstrates various aspects of creating a transactional service and

1. WCF uses the <xref:System.ServiceModel.ServiceBehaviorAttribute.ReleaseServiceInstanceOnTransactionComplete%2A> property to specify whether the underlying service instance is released when a transaction completes. Since this defaults to `true`, unless configured otherwise, WCF exhibits an efficient and predictable "just-in-time" activation behavior. Calls to a service on a subsequent transaction are assured a new service instance with no remnants of the previous transaction's state. While this is often useful, sometimes you may want to maintain state within the service instance beyond the transaction completion. Examples of this would be when required state or handles to resources are expensive to retrieve or reconstitute. You can do this by setting the <xref:System.ServiceModel.ServiceBehaviorAttribute.ReleaseServiceInstanceOnTransactionComplete%2A> property to `false`. With that setting, the instance and any associated state will be available on subsequent calls. When using this, give careful consideration to when and how state and transactions will be cleared and completed. The following sample demonstrates how to do this by maintaining the instance with the `runningTotal` variable.

```
```csharp
[ServiceBehavior(TransactionIsolationLevel = [ServiceBehavior(
ReleaseServiceInstanceOnTransactionComplete = false)]
public class CalculatorService : ICalculator
Expand All @@ -189,7 +189,7 @@ This sample demonstrates various aspects of creating a transactional service and
public double Add(double n)
{
// Perform transactional operation
RecordToLog(String.Format("Adding {0} to {1}", n, runningTotal));
RecordToLog($"Adding {n} to {runningTotal}");
runningTotal = runningTotal + n;
return runningTotal;
}
Expand All @@ -198,7 +198,7 @@ This sample demonstrates various aspects of creating a transactional service and
public double Subtract(double n)
{
// Perform transactional operation
RecordToLog(String.Format("Subtracting {0} from {1}", n, runningTotal));
RecordToLog($"Subtracting {n} from {runningTotal}");
runningTotal = runningTotal - n;
return runningTotal;
}
Expand Down
16 changes: 8 additions & 8 deletions docs/framework/wcf/feature-details/wcf-web-http-formatting.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,22 @@ public class Service : IService
[WebGet]
public string EchoWithGet(string s)
{
// if a format query string parameter has been specified, set the response format to that. If no such
// query string parameter exists the Accept header will be used
// if a format query string parameter has been specified, set the response format to that. If no such
// query string parameter exists the Accept header will be used
string formatQueryStringValue = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["format"];
if (!string.IsNullOrEmpty(formatQueryStringValue))
{
if (formatQueryStringValue.Equals("xml", System.StringComparison.OrdinalIgnoreCase))
{
WebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.Xml;
}
else if (formatQueryStringValue.Equals("json", System.StringComparison.OrdinalIgnoreCase))
if (formatQueryStringValue.Equals("xml", System.StringComparison.OrdinalIgnoreCase))
{
WebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.Xml;
}
else if (formatQueryStringValue.Equals("json", System.StringComparison.OrdinalIgnoreCase))
{
WebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.Json;
}
else
{
throw new WebFaultException<string>(string.Format("Unsupported format '{0}'", formatQueryStringValue), HttpStatusCode.BadRequest);
throw new WebFaultException<string>($"Unsupported format '{formatQueryStringValue}'", HttpStatusCode.BadRequest);
}
}
return "You said " + s;
Expand Down
17 changes: 6 additions & 11 deletions docs/framework/wcf/migrating-from-net-remoting-to-wcf.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ using (ServiceHost serviceHost = new ServiceHost(typeof(WCFServer), baseAddress)
serviceHost.AddServiceEndpoint(typeof(IWCFServer), binding, baseAddress);
serviceHost.Open();

Console.WriteLine(String.Format("The WCF server is ready at {0}.",
baseAddress));
Console.WriteLine($"The WCF server is ready at {baseAddress}.");
Console.WriteLine("Press <ENTER> to terminate service...");
Console.WriteLine();
Console.ReadLine();
Expand Down Expand Up @@ -115,8 +114,7 @@ RemotingServer server = (RemotingServer)Activator.GetObject(
"tcp://localhost:8080/RemotingServer");

RemotingCustomer customer = server.GetCustomer(42);
Console.WriteLine(String.Format("Customer {0} {1} received.",
customer.FirstName, customer.LastName));
Console.WriteLine($"Customer {customer.FirstName} {customer.LastName} received.");
```

The RemotingServer instance returned from Activator.GetObject() is known as a "transparent proxy." It implements the public API for the RemotingServer type on the client, but all the methods call the server object running in a different process or machine.
Expand All @@ -133,8 +131,7 @@ ChannelFactory<IWCFServer> channelFactory =
IWCFServer server = channelFactory.CreateChannel();

Customer customer = server.GetCustomer(42);
Console.WriteLine(String.Format(" Customer {0} {1} received.",
customer.FirstName, customer.LastName));
Console.WriteLine($" Customer {customer.FirstName} {customer.LastName} received.");
```

This example shows programming at the channel level because it is most similar to the Remoting example. Also available is the **Add Service Reference** approach in Visual Studio that generates code to simplify client programming. For more information, see the following topics:
Expand Down Expand Up @@ -263,8 +260,7 @@ try
}
catch (FaultException<CustomerServiceFault> fault)
{
Console.WriteLine(String.Format("Fault received: {0}",
fault.Detail.ErrorMessage));
Console.WriteLine($"Fault received: {fault.Detail.ErrorMessage}");
}
```

Expand Down Expand Up @@ -445,8 +441,7 @@ public class RemotingServer : MarshalByRefObject
new ChannelFactory<ICustomerService>("customerservice");
ICustomerService service = factory.CreateChannel();
Customer customer = service.GetCustomer(42);
Console.WriteLine(String.Format(" Customer {0} {1} received.",
customer.FirstName, customer.LastName));
Console.WriteLine($" Customer {customer.FirstName} {customer.LastName} received.");
```

Objects returned by WCF from the server to the client are always by value. The objects are deserialized copies of the data sent by the server. The client can call methods on these local copies without any danger of invoking server code through callbacks.
Expand Down Expand Up @@ -651,7 +646,7 @@ public class RemotingServer : MarshalByRefObject
CustomerId = 43,
AccountId = 99};
bool success = service.UpdateCustomer(customer);
Console.WriteLine(String.Format(" Server returned {0}.", success));
Console.WriteLine($" Server returned {success}.");
```

The customer object will be serialized, and sent to the server, where it is deserialized into a new copy of that object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public class CustomTextMessageEncoder : MessageEncoder

this.writerSettings = new XmlWriterSettings();
this.writerSettings.Encoding = Encoding.GetEncoding(factory.CharSet);
this.contentType = string.Format("{0}; charset={1}",
this.factory.MediaType, this.writerSettings.Encoding.HeaderName);
this.contentType = $"{this.factory.MediaType}; charset={this.writerSettings.Encoding.HeaderName}";
}

public override string ContentType
Expand Down
Loading