WCF: A utility to change all URLs in .config files by one click

Hello,
Before Dublin is in charge, especially the Repository for the Web-services I’m using the custom code to manage the buzz with many URLs in Web.config files
There is a utility to change all URLs in .config files by one click.

1. Purpose.
In my current project we’ve got a lot of composite WCF-services. We have several environments: Development,Test1, Test2, Production.
We don’t have the service repository. That means when we move the services from one environment to another, we have to change addresses (URLs) in the <client> sections of all Web.config files (several dozens). Boring and error prone work, isn’t it?
The FilesModificatorAdmin utility was created to change all addresses in all Web.config files by one click.

2. How it works.
We define the files that should be scanned and changed. We define the root folder for search. We define the replacements substrings like “http://Env1.MyCompany.com/Composite/Promo/PromoService.svc”. The utility derives the searching substring RegExes from the replacement substrings like “”http[^\”]*?PromoService.svc”.
Then the FilesModificatorAdmin utility scans all defined files in all folder tree and replace the substrings.
Utility creates the copy of the changed files as OldName.copy.
Utility output the progress to the screen and optionally to the log file.
Utility could optionally just scan the files and show how many searching substrings were found and where.
3. Notes.
* The rules to derive the RegEx for the search are hard coded.
* If the FilesModificatorAdmin found the searching substrings but the string does not changed (it is possible because the searching sub string RegEx could find the substring that is equal the replacement substring) the FilesModificatorAdmin does not change the substring. In this case it shows that sub strings were found if option the “find only and do not replace the Substrings” is checked, and it shows that substrings were not found if option the “find only and do not replace the Substrings” is unchecked.

GLD (C) 2008

Simple Reflection Based Assignment Using Extension Methods

Have you ever had two objects, of different types, and wished that C# could just be smart enough to realize that objA.FirstName should be assigned to objB.FirstName?  For me this comes up quite a bit when working with WCF services.  I don’t want a service to directly expose my internal business object type, because that type might change on a different schedule than that of my data contract.  So I often end up with objects that have identical property names, usually the service being a subset of the internal class, but obviously of different types.  How can I handle assigning objDC from objInternal without writing a line of code (or generating a line of code) for every single property?  Enter AssignFrom … with this code, you’ll get something as simple as objDC.AssignFrom(objInternal);

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Diagnostics;

namespace TestCSharp
{
    public static class ObjectExtensions
    {
        public static T AssignFrom<T>(this T obj, object from)
        {
            Type toType = obj.GetType();
            Type fromType = from.GetType();

            var toInfo = toType.GetProperties();
            var fromInfo = fromType.GetProperties();

            foreach (var fromProp in fromInfo)
            {
                bool assigned = false;
                foreach (var toProp in toInfo)
                {

                    if (toProp.CanWrite && fromProp.CanRead &&
                        toProp.PropertyType.Equals(fromProp.PropertyType) &&
                        toProp.Name.Equals(fromProp.Name) &&
                        toProp.GetIndexParameters().Count() == 0 &&
                        fromProp.GetIndexParameters().Count() == 0)
                    {
                        toProp.SetValue(obj, fromProp.GetValue(from, null), null);
                        assigned = true;
                    }
                }

                Debug.Assert(assigned, 
                    string.Format(
                    "Property {0} was not populated to the To object.", 
                    fromProp.Name));
            }

            return obj;
        }
    }
}

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

Screencasts – Creating Your First WCF Client

Screencasts – Creating Your First WCF Client

Welcome back to the WCF screencast series! After a spending four weeks covering WF topics, we return to WCF for the latest video in the weekly WF/WCF Screencast series. In the coming month, we’ll be covering topics around the calling of WCF services.

This week, CSD MVP Aaron Skonnard from PluralSight guides the viewer through how to create your first WCF client application that consumes an existing WCF service (see the screencasts covering the creation of a WCF service and how to create endpoints for more details). We add the service to the client application using the WCF service’s Metadata Exchange (MEX) endpoint – which generates the service definition and contract, which Aaron then writes the code to consume via code…and how to have VS2008 open up your client as the test client at F5 (debug) instead of the standard WCF test client when the service is launched.

As he shows you how to write the client side code, he touches on how the service endpoint information is stored in the config files and storing the results back from the WCF service in local .NET object classes.

Watch the Screencast 

As mentioned above, the WCF screencasts are a weekly series of Channel9 videos done in conjunction with the folks at PluralSight to help developers new to WF/WCF see how the technology is used. It’s worth noting that Aaron and the PluralSight folks are now offering online training courses (in a format similar to these screencasts) as a compliment to their catalog of instructor-led training courses covering Microsoft connected systems technologies. Their training topics range from .NET v3.5 (including an excellent WF/WCF Double Feature course) to WSS to BizTalk server.

WSCF Blue is now open

Christian Weyer has now announced that WSCF-Blue the code name for the next version of WSCF – Web Services Contract First is now an open project on CodePlexand is looking for people to participate and take the lead on driving the tool forwards.
In case you havent come across it so far, WSCF is a really […]

WCF and WF at the PDC 2008

I know a lot of you are excited about attending PDC2008 from the 27th through the 30th of October .


There are some very interesting sessions at the PDC this year, I wanted to draw your attention to some of the sessions by members of my team.




  • WCF 4.0: Building WCF Services with WF in Microsoft .NET 4.0  Presenter: Ed Pinto



  • WF 4.0: A First Look Presenter: Kenny Wolf




  • Microsoft .NET Framework: Declarative Programming Using XAML Presenters: Rob Relyea, Daniel Roth





  • Workflow Services: Orchestrating Services and Business Processes Using Cloud-Based Workflow Presenter: Moustafa Ahmed






  • WF 4.0: Extending with Custom Activities Presenter: Matt Winkler







  • WCF: Developing RESTful Services Presenter:Steve Maine





If you haven’t registered yet to attend the PDC, this is your last chance click REGISTER

 


Ravi

Multiple ways to Poll (Receive Location in BizTalk) in the SQL Adapter

In this post, I outlined the ways in which stored procedures can be executed using the SQL Adapter. Similar to the methods described there, are very similar methods for polling on the inbound side. (I won’t mention the advantages/limitations/workarounds here, since there are very similar to those mentioned in the other post).

1. The first method for polling, manifested as the “Polling” operation in the Metadata Search/Browse tool. At runtime, the SQL statement specified in the “PollingStatement” binding property gets executed, and the result sets returned (we support multiple result sets being returned) are surfaced as System.Data.DataSet[] (an array of datasets).

NOTE – in order to let the adapter know that you want it to perform this operation at runtime, set the InboundOperationType binding property to Polling.

2. The next approach was to try and expose the result sets as “strongly typed”. For this purpose, we added the “TypedPolling” operation which you can see in the Metadata UI. Metadata is obtained (at design time + runtime) using ADO.NET’s CommandBehavior::SchemaOnly option (which translates to SET FMTONLY ON).

NOTE – in order to generate the metadata, setting the InboundId property in the Connection Uri is mandatory – since in a single BizTalk application, you can have multiple receive locations with different PollingStatement values, and in order to differentiate the XSDs, the InboundId value is used (thus, the InboundId should be different for different Receive Locations)

NOTE – in order to let the adapter know that you want it to perform this operation at runtime, set the InboundOperationType binding property to TypedPolling.

3. In CTP4 (releasing end of October 2008), we’ve added one more mechanism. This was mainly done for backward compatibility.

In this method, the PollingStatement you specify should return data in XML format (e.g., SELECT Col1 FROM Table1 FOR XML AUTO). At runtime, the XML data returned is enclosed within the root tag defined by the values in the binding properties XmlStoredProcedureRootNodeName and XmlStoredProcedureRootNodeNamespace.

NOTE – in order to let the adapter know that you want it to perform this operation at runtime, set the InboundOperationType binding property to XmlPolling.