When using the .NET Framework 3.5, a workaround is required to use a WCF service application with Solver Foundation. Without this workaround, the application may cause a configuration exception: "exePath must be specified when not running inside a stand alone exe". The workaround involves creating a web service to wrap the service application. NOTE: this workaround is not required for users of .NET Framework 4.

For example, consider a WCF service application OptimizationService that uses MSF with a contract Solve. Here is a code sample that illustrates this with a simple optimization problem:

[OperationContract]

public string Solve() {

SolverContext context = SolverContext.GetContext();

//decisions

Decision xs = new Decision(Domain.RealNonnegative, "Number_of_small_chess_boards");

Decision xl = new Decision(Domain.RealNonnegative, "Number_of_large_chess_boards");

model.AddDecisions(xs, xl);

//constraints

Constraint constraintBoxWood = model.AddConstraint("BoxWood", 1 * xs + 3 * xl <= 200);

Constraint constraintLathe = model.AddConstraint("Lathe", 3 * xs + 2 * xl <= 160);

//Goals

model.AddGoal("Profit", GoalKind.Maximize, 5 * xs + 20 * xl);

Solution sol = context.Solve();GetContext();

Model model = context.CreateModel();

Report report = sol.GetReport();

return sol.GetReport().ToString();

}

Now to use OptimizationService from any application, create a ASP.Net web service OptimizationWebService that defines a web method Solve. The web method Solve invokes the WCF service OptimizationService defined above.

[WebMethod]

public string Solve() {

//Direct call to service

OptimizationService service = new OptimizationService();

string value = service.Solve();

//or Call to a proxy client

//OptimizationServiceClient client = new OptimizationServiceClient();

//string value = client.Solve();

return value;

}

Now any client code can call the web service to access the WCF application service.