Category: SOA

  • Interview Series: Four Questions With … Tomas Restrepo

    There are a plethora of great technologists in the “connected systems” space, and I thought it would be fun to interview a different one each month.  These are short, four question interviews where I ask about experiences with technology.  The last question will always be a fairly stupid, silly question that might only amuse me.  So be it.  I used to do these sorts of interviews when I wrote newsletters for Avanade and Microsoft, so if I happen to reuse a previously asked stupid question, it’s because I liked it, and assume that most of my current readers never saw those old newsletters.  I’m a cheater like that.

    To start things off, let’s have a chat with Tomas Restrepo.  Blogger extraordinaire , Microsoft MVP, and all around good guy.

    Q: Tomas, you’ve consistently been out in front of many Connected Systems technologies such as BizTalk Server and WCF.  What Microsoft technologies are on your “to do” list, why, and how do you plan to learn them?

    A:  That’s really a tough question to answer. There’s just so much stuff coming out of Redmond these days, and, to be honest, it’s still to early to tell yet how much of it is going to “stick” and what might be abandoned down the road in favor of something else.

    Sometimes learning a new technology in depth can be quite time consuming, so you want to be careful when choosing what to invest your time in. What I’m currently trying to do is follow a few rules:

    • Try to be aware of “what’s out there” and at least know what it does and what it is good for.
    • Figure out which things are interesting enough (or show enough potential) to dig into a bit deeper. Not enough to master them, but enough to know the big concepts behind them and how to apply them.
      These are stuff you play with a little bit, and would consider good enough to start a POC with them if the need arises and then dig into them big time when you start a project with them.
    • Stuff that’s really important that you want to really spend a lot of time tinkering with them and mastering them.

    I think there are some interesting things out there worth keeping an eye on. For example, I don’t do much web development these days, but if I had to, I’d immediate dig deeper into the ASP.NET MVC framework. I’m already familiar with Castle’s monorail and somewhat with rails and other similar technologies, so it should be easier to get started.

    I’m also definitely looking forward to some of the stuff in Oslo. Obviously the core framework and WCF stuff is going to be pretty interesting there. I’ve been keeping an eye on the cloud services (BizTalk Services) stuff as well, but I’m really waiting there for a project idea that really demands those capabilities before spending more time with them.

    Certainly there’s a lot of things that will be coming out in the next one-two years such as the updates to the big products (SQL, Visual Studio and so on), and those will get their fair share of time when the time comes.

    Q: In your experience, what is your criteria for deciding between either using (a) a broker such as BizTalk Server between systems or (b) directly consuming interfaces/services between systems?

    A:  I think this is one case where there are both technical and non-technical reasons for making this decision.

    On the technical side I very much try to start questioning whether any kind of mediation is required/desired and whether BizTalk is the right kind of tool for that job. In particularly, I’d look into the latency and performance requirements, the protocols being used for the services and the amount of data that needs to be transferred between systems.

    Part of this is looking to see if, for example, the project is in a low-latency scenario or perhaps if it’s really a set of bulk data processes more suitable to something like SSIS.

    Another thing to look for is whether you need the kind of capabilities that BizTalk offers. For example, would the interface be better served with Pub/Sub support? Would the Pub/Sub support in BizTalk be enough, or does it require heavier duty pub/sub with thousands of subscribers and possibly transient (non-persistent) subscriptions?

    BizTalk has some great support for some kind of messaging scenarios, but it also has limitations that can constrain your solution heavily. Sometimes you can clobber your project needs into BizTalk by extending the product in different ways (thank goodness for its extensibility!), but it’s not always the best option available.

    On the non-technical side, a few aspects that matter are: Does the client already own a BizTalk license they can use? If not, can the project/client budget take assume that cost? Sometimes it can be negotiated, but other times it’s just not an option. Besides the raw cost of licensing, there are of course knowledge aspects, like, does the company have people already familiar with the technology?

    In other words, I’ve found that the non-technical aspects of the use/don’t use BizTalk aren’t too different from the kind of aspects you’d consider for acquisition of any new technology. That said, BizTalk does pose it’s own challenges on an organization because of it’s complexity.

    That said, I do try to be very careful to avoid looking at the world with technology-tainted glasses. It’s important to approach a new project with an open mind and figure out what the best technology to solve the client needs are, instead of starting with a given technology (BizTalk, in this case) and try to cram the project requirements into it whatever the cost. Sometimes the non-technical aspects of the project might suggest/impose a technology decision on you, but even in that case it’s important to take a step back, breath deeply and make sure it’s the best option available to you.

    Q: You’ve been working with a variety of non-Microsoft technologies lately.  What are some of the interoperability considerations you’ve come across recently?  Share any “gotchas” you’ve encountered while getting different platforms to play nicely together.

    A:  No matter how you look at it, interoperability isn’t easy, and you can’t take it for granted. It’s something you need to keep very much in check every step of the way and verify it time and time again.

    Certainly Web Services (of both the SOAP and REST varieties) have helped here somewhat, but not all interoperability issues come from the lower-level transport protocols; sometimes the application / service interface design can have a bit impact on interoperability.

    One rule I try to follow is to design for interoperability. For example, if I’m designing a new service interface, I want to know who my clients are going to be; what technology they are going to be using and what constrains they might have.

    Sometimes, the best option you can take is to stick to the basics: simple works. That’s actually one of the beauties of REST architectures. As long as you’ve got an XML parser and an HTTP client, you’re in business, and HTTP is known well enough (and has such a good tooling around it for development and diagnosis) that it really helps a lot.

    Basic SOAP is also pretty good nowadays, if used correctly. The WS-* specs, like WS-Security and friends are pretty important in some scenarios. They are published standards, yes, but getting interoperability isn’t as easy as with plain SOAP and rest, because they are very complex specifications.

    For example, if you’re using message-level encryption, and you run into trouble, then raw protocol level interception won’t help you at all to diagnose the issue; you really need tooling support on your SOAP stack for this (WCF’s is pretty good).

    Once you get into using X.509 certificates for encryption/signing or even just for raw authentication, things can get hairy pretty quickly. Mostly this is because a lot of people don’t quite understand how X.509 certificate validation works, and common problems arise from invalid certificates, certificates installed to the wrong store, or just because someone forgot to deploy the entire certificate trust chain.

    By themselves, they are not though problems to solve, but diagnosing them can be very challenging at times because the tooling isn’t always very good at reporting the right reasons for failure. Anyone who has been stuck with a “Error validating server identity” kind of error can attest to that 🙂

    WS-Security specs also have the pose another challenge, and it’s that there are multiple versions of those specs out there, and sometimes you find yourself using one version with your partner using another. You have to be very careful in specifying and validating the right protocol version.

    Q [stupid question]:  Everyone has that one secret pet peeve that makes them crazy.  I’ll admit that mine is “mysterious stickiness.”  I shudder at the thought of touching a surface and coming away with a unwanted adhesive.  Ugh.  Tell us, what is something that really drives you nuts?

    A: Cockroaches. I hate cockroaches. They give me the creeps.

    Seriously speaking, though, I think that my main problem is that I can be very impatient about the little things. Stuff like getting short delays from things can drive me crazy (a stuck keyboard or mouse can really go out of this world).

    Hope you all find these interviews a bit interesting or at least mildly amusing.

    Technorati Tags: ,

  • Checklist for Reviewing Services for SOA Compatibility

    I’ve got SOA on the brain lately.  I’m in the process of writing a book on building service-oriented solutions using BizTalk Server 2006 R3 (due out right around the product release), and, trying to organize a service review board at my company.  Good times.

    So what’s a “service review board”?  It’s a chance to look at services that have been deployed within our development environment and chat with the developer/architect about various design and deployment considerations.  In reality, it’s a way to move from “just a bunch of web services” (JBOWS) to an architecture that truly supports our stated service-oriented principles.  Now, clearly there are services that are meant to solve a specific purpose, and may not be appropriate for “enterprise” scale.  But, I would argue that the goal of any service is to be designed with principles of reuse in mind, even if service reuse never happens.

    Who should attend such a review board besides the service developer?  I’d suggest the following representatives:

    • Infrastructure.  Make sure that all deployment considerations have been taken into account such as a host server (dev/test/prod), required platforms and the like.
    • Enterprise architecture.  Look at the service and compare that to other enterprise projects to see if there is overlap with existing services, or, the possibility to reuse the new service in an upcoming project.
    • Data architecture.  Confirm best practices for the data being sent as part of service requests or responses.   Also, consider the data security and data privacy.
    • Solution architecture.  Review software patterns used and ensure that the service has the appropriate security considerations and repository registration.

    With that in mind, what questions do we want to ask to verify whether this service is enterprise-ready?

    Infrastructure
    Question Answer
    What is the technology platform that this service is built upon (e.g. Java, .NET)?  
    Do you have host servers identified for all deployment environments?  
    Are there any SLAs defined for this service as a result of non-functional requirements?  
    Have the appropriate service repository metadata elements been identified for this service?  
    Has this service been sufficiently load tested?  
    Security
    Question Answer
    Has a security policy been identified?  
    Does this service use either transport-level security or message-based security, and if so, does it match corporate standards?  
    Have the appropriate directory accounts/groups been created and assigned?  
    Data
    Question Answer
    What type of data is received by the service: document, event or function parameter?  
    Are the input/output types complex or simple types?  
    Were standard, cross-platform data types used?  
    Does this service use an enterprise shared entity as its input or output?  
    If the answer above is “no”, should the input/output parameter be considered for a new shared entity definition?  
    Is the input message self-contained?  
    Software Architecture
    Question Answer
    Is this a data service, event service, or functional service?  
    Does it support both synchronous and asynchronous invocation?  
    Is the service an encapsulated, stand-alone entity?  
    Are service dependencies dynamically loaded or configurable?  
    Has the service been tested for cross-platform invocation?  
    Does this service use an transactions?  
    Can the service accept a flowed transaction?  
    Has a lifecycle versioning strategy been defined?  
    Is the interface SOAP, REST or POX based?  
    Do common functions like exception handling and logging use enterprise aspects?  
    Is the service contract coarse grained or fine grained?  
    Is the WSDL too complicated (e.g. numerous imports) to be consumed by BizTalk Server?  
    How are exceptions handled and thrown?  
    Does the service maintain any state?  
    Do the service namespace and operations have valid and understandable identifiers?  

    The goal of this is not to torture service developers, but rather to consider enterprise implications of new services being developed.  Did I miss anything, or include something that doesn’t matter to you?  I’d  love your thoughts on this.

    Technorati Tags:

  • New WCF Management Pack for SOA Software

    I was on a conference call with those characters from SOA Software and they were demonstrating their BizTalk Management Pack.  They also spent a lot of time covering their in-development WCF binding.

    Moving forward, SOA Software is releasing Microsoft-friendly agents for …

    • IIS 6.0 (SOAP/HTTP)
    • WCF (any transport)
    • BizTalk (any transport)
    • BizTalk-WCF (any transport)

    All of these (except the BizTalk agent) support policy enforcement.  That is, the BizTalk agent only does message recording and monitoring whereas the other agents support the full suite of SOA Software policies (e.g. security, XSLT, etc).

    So what is the difference between the BizTalk agent, and the BizTalk-WCF agent?  The relationship can be represented as such:

    The BizTalk-only agent is really a pipeline component which captures things from inside the BizTalk bus.  This means that it will work with ANY inbound our outbound adapter.  Nice.  The SOA Software WCF binding is at the WCF adapter layer, and allows for full policy enforcement at the adapter layer.  However, this is ONLY for the BizTalk WCF adapters, not the other adapters.

    So if I had a WCF endpoint that I wanted to play with SOA Software, I could first attach the out-of-the-box SOA Software pipelines to the receive location.

    Next, in the WCF-CustomIsolated adapter configuration, I can specify the new soaBinding type.

    I don’t HAVE to do the pipeline AND the WCF binding if I have a WCF endpoint, but, if I want to capture the data from multiple perspectives, I can.  For that binding, there are a few properties that matter.  Mostly importantly, note that I do NOT have to specify which policy to apply.  The appropriate policy details are recovered at runtime, so making changes to the policy requires no changes to this configuration.

    From within the SOA Software management interface, I can review my BizTalk endpoints (interpreted as operations on a WSDL that represents the BizTalk “application”).

    Notice that this is a managed BizTalk receive location.   If I sent something through this managed receive location (with a policy set to record and monitor the traffic) I could see a real-time chart of activity, and, see the message payload.

    Notice that I see all the context values, AND, the payload in a CDATA block.  This supports BizTalk flat file scenarios.

    As for the WCF binding, you would install the SOA WCF binding on the client machine, and it becomes available to developers who want to call the SOA-managed WCF service.  The binding looks up the policy details at runtime, again shielding the developer from too much hard coding of information.

    So what’s cool here?  I like that the BizTalk agent works for ALL BizTalk adapters.  You can create a Service Level Agreement (SLA) policy where more than 10 faults to an Oracle adapter send port results in an email to a system owner.  Or if traffic to a particular FILE receive location goes above a certain level (per day), then raise an issue.  From the WCF side, it’s very nice that all WCF transports are supported for service management and that service policy information is dynamically identified at runtime versus embedded in configuration details.

    If you’re a BizTalk shop, and you have yet to go nuts with SOAP and services, you can still get some serious value from using the BizTalk agent from SOA Software.  If you’ve fully embraced services, and are already on the WCF bandwagon, the upcoming WCF binding from SOA Software provides a vital way to apply service lifecycle and management to your environment.

    Technorati Tags: , , WCF

  • All Source Code Posted for BizTalk + WCF Articles

    I just finished zipping up all the source code for my recent set of articles over at TopXML.com.  Specifically, I just added the source code for the set of articles on publishing WCF services out of BizTalk (with security, transactions, attachments) and the source code for all the BizTalk Adapter Pack demonstrations that utilized the Oracle adapter.  I make no promises that the code is attractive, contains best practices, or avoids the use of obscenities in the comments.

     

    Series Summary
     BizTalk and WCF: Part I, Operation Patterns Get the source code!
     BizTalk and WCF: Part II, Security Patterns
     BizTalk and WCF: Part III, Transaction Patterns
     BizTalk and WCF: Part IV, Attachment Patterns
     BizTalk and WCF: Part V, Publishing Operations Patterns Get the source code!
    BizTalk and WCF: Part VI, Publishing Advanced Service Patterns
    BizTalk and WCF: Part VII, About the BizTalk Adapter Pack Get the source code!
    BizTalk and WCF: Part VIII, BizTalk Adapter Pack Service Model Patterns
    BizTalk and WCF: Part IX, BizTalk Adapter Pack BizTalk Patterns

     

    Technorati Tags: ,

  • Article on Choosing Service Implementation Strategy with WCF

    Michele recently wrote a lengthy but deliciously thorough article on MSDN (hat tip: Lynn) called Application Deployment Strategies which identifies five core scenarios for using Windows Communication Foundation within a distributed application.  Those scenarios include:

    1. Enterprise web services.   Think secure, interoperable services that may also utilize new-ish WS* standards such as WS-AtomicTransaction and WS-ReliableMessaging.
    2. Web 2.0 services.  These are your POX or REST services with a look at JSON and RSS/ATOM.
    3. Intranet applications.  These services which live inside your own organization may use something like TCP as a transport.  Or, if you’re like my company, even the internal web service standard is SOAP over HTTP.
    4. Queued messaging.  If you have asynchronous or offline messaging needs, you can look at MSMQ with WCF.  She also touches on “pub/sub” scenarios and discussing building ESB-like capabilities.
    5. Workflow services.  If you’re building workflow-based applications using WF, there are considerations for exposing services from those workflows.

    For each scenario, Michele nicely calls out the implementation characteristics (e.g. hosting environment, authentication, etc), configuration details, and a set of common questions and answers (e.g. “What other credential types are supported for web services?” or “When should I use a reliable session?”).

    The formatting of the article itself makes it a bit tricky to understand which header topic you’re currently under, but, I’m sure you’re smart enough to figure it out.

    Technorati Tags: ,

  • Article Series on BizTalk and WCF: Part IX, BizTalk Adapter Pack BizTalk Patterns

    UPDATE: I have since moved these articles to my own blog and they can be found here.

    Whew.  My 9th and final article for TopXML.com on integrating BizTalk Server and WCF is now published.  This one looks at the BizTalk Adapter Pack and how to consume the Oracle adapter from inside BizTalk Server.  I demonstrated how to insert multiple records at once, call stored procedures, build a database polling solution, and how to call the Adapter Pack from an orchestration using code.

    20,500+ words and 178 screenshots later, I definitely learned a lot about WCF (and Oracle) by writing this series of articles.  I found the security and attachment topics to be challenging, the transaction topics to be quite interesting, and the BizTalk Adapter Pack to be quite compelling.  The WCF integration in BizTalk Server 2006 R2, while not as rich as it could be, is actually pretty darn well built and thought out.

    When I started out on this series, I figured that writing about BizTalk/WCF and then the BizTalk Adapter Pack would be somewhat “niche” for the majority of developers, but, hopefully this helps people down the line as they begin to really investigate and evaluate these technologies together.

    Series Summary
     BizTalk and WCF: Part I, Operation Patterns Get the source code!
     BizTalk and WCF: Part II, Security Patterns
     BizTalk and WCF: Part III, Transaction Patterns
     BizTalk and WCF: Part IV, Attachment Patterns
     BizTalk and WCF: Part V, Publishing Operations Patterns Get the source code!
    BizTalk and WCF: Part VI, Publishing Advanced Service Patterns
    BizTalk and WCF: Part VII, About the BizTalk Adapter Pack Get the source code!
    BizTalk and WCF: Part VIII, BizTalk Adapter Pack Service Model Patterns
    BizTalk and WCF: Part IX, BizTalk Adapter Pack BizTalk Patterns

     

    Technorati Tags: ,

  • Article Series on BizTalk and WCF: Part VIII, BizTalk Adapter Pack Service Model Patterns

    UPDATE: I have since moved these articles to my own blog and they can be found here.

    So how would you use the BizTalk Adapter Pack to build a RESTful HTTP URI on top of an Oracle database table?  What about calling Oracle stored procedures that made use of either strong or weak ref cursors?  In my latest article for TopXML.com,  I explore how to consume the Microsoft BizTalk Adapter Pack’s Oracle adapter using the WCF service model.

    Specifically, I show how to …

    • Insert multiple records into an Oracle table using a single WCF operation call
    • Call Oracle stored procedures and process their result sets in either a strongly typed or weakly typed fashion
    • Using the adapter’s “polling” mechanism to build an Oracle database polling WCF host
    • Apply RESTful WCF attributes from the .NET Framework 3.5 to the BizTalk Adapter Pack

    This was a fun article to write.  The ability of the adapter to poll an Oracle database and kick off an event introduces a number of possibilities.  Also, applying  some of the things that I had read about the new RESTful WCF attributes with the auto-generated Oracle adapter bits proved to me a useful exercise.

    Feedback?  Let me know.

     

    Series Summary
     BizTalk and WCF: Part I, Operation Patterns Get the source code!
     BizTalk and WCF: Part II, Security Patterns
     BizTalk and WCF: Part III, Transaction Patterns
     BizTalk and WCF: Part IV, Attachment Patterns
     BizTalk and WCF: Part V, Publishing Operations Patterns Get the source code!
    BizTalk and WCF: Part VI, Publishing Advanced Service Patterns
    BizTalk and WCF: Part VII, About the BizTalk Adapter Pack Get the source code!
    BizTalk and WCF: Part VIII, BizTalk Adapter Pack Service Model Patterns
    BizTalk and WCF: Part IX, BizTalk Adapter Pack BizTalk Patterns

    Technorati Tags: ,

  • Article Series on BizTalk and WCF: Part VII, About BizTalk Adapter Pack

    UPDATE: I have since moved these articles to my own blog and they can be found here.

    I just posted another article for TopXML.com as part of my series on BizTalk + WCF.   In this article, I explore the new BizTalk Adapter Pack.

    This article is mainly an introduction to the BizTalk Adapter Pack, with a couple demonstrations using the Oracle adapter.  I show how to use the WCF Oracle adapter to query Oracle data using both standard .NET code and and a BizTalk project.

    Next up, I’ll close out the series with a couple articles highlighting key use cases for the Adapter Pack and how to execute those use cases via code or BizTalk.

     

    Series Summary
     BizTalk and WCF: Part I, Operation Patterns Get the source code!
     BizTalk and WCF: Part II, Security Patterns
     BizTalk and WCF: Part III, Transaction Patterns
     BizTalk and WCF: Part IV, Attachment Patterns
     BizTalk and WCF: Part V, Publishing Operations Patterns Get the source code!
    BizTalk and WCF: Part VI, Publishing Advanced Service Patterns
    BizTalk and WCF: Part VII, About the BizTalk Adapter Pack Get the source code!
    BizTalk and WCF: Part VIII, BizTalk Adapter Pack Service Model Patterns
    BizTalk and WCF: Part IX, BizTalk Adapter Pack BizTalk Patterns

    Technorati Tags: ,

  • Using the BizTalk Adapter Pack to Load Oracle Data into InfoPath 2007 Forms

    One of the glaring omissions from InfoPath 2007 is integration with non SQL Server data repositories.  For retrieving reference data (query data), your only choice is SQL Server.  That’s lousy.  For submitting data, your only choice is SQL Server or Microsoft Access, and, you can only submit to a database when using the thick client version of InfoPath.  That is, you can’t do a direct database submission on the InfoPath Forms Services version of a form.  This also sucks.  SharePoint isn’t much better, as the SharePoint Designer integration with ODBC data sources (such as Oracle) is clumsy at best, and in our experience, not really functional.

    But, complaining gets me nowhere.  So, how can I cleanly interface between InfoPath and Oracle, which is the overwhelming database preference in my current environment?  What I’ll show here is how to use the BizTalk Adapter Pack to generate the service stubs I need to query and publish to Oracle databases.  I’ll be publishing another article on TopXML.com that digs deeply into the BizTalk Adapter Pack, so I won’t go into great depth here on what it is.   But the short description is:  the BizTalk Adapter Pack contains Line of Business (LOB) adapters that use a common WCF infrastructure which can be consumed by WCF clients, ADO.NET clients (for ETL scenarios), BizTalk clients (for robust workflow, EAI scenarios), or basic SOAP clients (for single operation scenarios).  I’m building an example for the last option.

    First off, I need data in my Oracle database tables.  If you are a regular Visual Studio.NET user, you know that you can access ODBC data sources (such as Oracle) using the built-in Server Explorer.  This works fine for data entry, but if you want true control over the database, you need more.  One really nice option (from Oracle itself) is the Oracle Developer Tools for Visual Studio.   This is a nice plug in for VS.NET that gives you most of what you need for Oracle design tasks.

    Lots of great stuff in there.  For my purposes, I needed a new table to start with.

    Then I had to fill in some initial data.

    Now we can actually build the service which interacts with this table.  First, I created a new “WCF Service Library” project in Visual Studio.NET.  From there, once the BizTalk Adapter Pack is installed, I can select Add Adapter Service Reference from the “Add” menu.

    This opens a window where I can select my connection criteria, browse objects in my repository, and select the operations I want.  The first thing to do is configure the URI.  After choosing which binding to use (in my case, the OracleDbBinding), I have to set the DataSourceName value.  This is the identifier in my Oracle tnsnames.ora file.  We no longer use System DSN entries to connect to Oracle and instead put database details in the tnsnames.ora file.  After setting the data source, I have to put the username and password for my Oracle database.

    Once all my connection details are set, I can connect to my database.  Now, I can search (*new feature alert*) and browse the database tables, views, functions, packages and procedures.

    After choosing my database table operation (“Select”) and closing out the window, I get an auto-generated application configuration file, and, a class containing all the interfaces, contracts and proxy code needed to consume this database service.  Now, as stated earlier, I want to take this WCF service, and expose it out for basic SOAP clients (i.e. InfoPath/SharePoint).  Before building the web service proxy around this WCF client, I want to add a brand new service interface.  I don’t want to directly expose the Adapter Pack interface, but rather, put a simpler interface out to my SOAP clients.

    So, in this WCF Service Library project, I added a new class containing a WCF ServiceContract and OperationContract, as well as the service which implements those contracts and calls my auto-generated Adapter Pack proxy.

    So I have a friendly service interface which abstracts some of the BizTalk Adapter Pack details, but calls the auto-generated Oracle Adapter bits when it’s operation is invoked.

    Now, I need to put this service into a web-ready container.  All I have now is the library project.  So, I created a new “Web Site” project of type “WCF Service.”  I don’t need much from this service, so the underlying “cs” file can be deleted.  Then, after adding a reference to my WCF Service Library project, I have to modify the Service.svc file so that it points at my implementation class (“Seroter.Demo.BizTalkAdapterPack.CustomerSvcLibrary.CustomerQuery”) for it’s “Service” attribute.    After this, all that remains is to set up the web.config file to both see my Oracle Adapter endpoint (as a service) and expose new endpoints for my SOAP clients.  After copying the information from the auto-generated app.config file (that should still be in the WCF Service Library project) into my web.config, I can launch the Service Configuration Editor to make the remaining web.config changes.  Specifically, I need to add a new service (and endpoint), and provide a metadata behavior so that clients can query the service metadata.

    So now I have a client endpoint (which uses the BizTalk Adapter Pack Oracle binding), and a new service with an HTTP endpoint that basic SOAP clients can use.  After creating a new virtual directory in IIS 6.0, and pointing to the WCF Service project, I now have a ready-to-go database access service.

    From InfoPath 2007, I can now call and consume this service to pull reference data from Oracle.  Specifically, I created a new data connection, pointed to the IIS service, and chose the operation I needed.

    Now I can drag the repeating results node to the InfoPath form and create a table.  If I preview the form, the service gets called, and the results are displayed.

    That was easy!  Took about a dozen lines of code and a configuration file setup.   In a later post, I’ll show how to use this service to populate data forms in SharePoint as well.

    Technorati Tags:  ,

  • Gracefully Uploading to SharePoint 2007 From BizTalk Server 2006 R1

    Scenario: I want to allow BizTalk Server 2006 (R1) to send XML (InfoPath forms) to a MOSS 2007 document library without resorting to hacks.

    Resolution: I can’t use the out-of-the-box BizTalk SharePoint adapter (only BizTalk Server 2006 R2 works natively with MOSS 2007) so I decided to utilize the available SharePoint web services to upload my file.  I wrote a wrapper web service to (a) encapsulate some additional logic (b) shield the BizTalk developer from understanding SharePoint services and (c) require no usage of the SharePoint 2007 object model.

    What did this solution look like?  I decided to use the CopyIntoItems method available on the SharePoint Copy web service.  This allows you to send a byte array of data to a document library and have it appear as a new document.  To hit the WSDL for this service, you’d go to:

    http://<your sharepoint base url>/sites/<site name>/_vti_bin/Copy.asmx

    Here you’ll see the CopyIntoItems operation.  My wrapper service starts with a couple “using” statements …

    using System.Net;   //for NetworkCredentials object
    using System.Text;  //for encoding bytes
    using System.IO;    //for stringwriter
    using System.Xml;

    Next I have my wrapper operation …

    [WebMethod]
    public string UploadXmlToSharePoint(string docToUpload,
    string siteRoot,
    string docLibrary,
    string fileName,
    string userName,
    string password,
    string domain)

    I’m taking the XML document input as a string in order to make the schema easier in BizTalk, and, ensure I don’t lose my InfoPath processing instructions when transporting over the wire (which seemed to be happening when I used an XmlDocument type input parameter).  Also note that I’m taking in a user/password/domain combo.  This is to allow for reuse later down the line.  The account used to call the SharePoint service MUST be a site administrator, so I’m making it an explicit parameter. The first thing I do inside my operation is build up the destination Uri based on the input parameters.

    //build full destination Url
    string destinationPath = siteRoot + "/" + docLibrary + "/" + fileName;

    Next I have to take the input string and convert it to the byte array required by the MOSS web service …

    //convert string to byte array
    byte[] fileIn = ConvertDocToBytes(docToUpload);
    ...
    private byte[] ConvertDocToBytes(string xmlString)
        {
            ASCIIEncoding encoding = new ASCIIEncoding();
    
            return encoding.GetBytes(xmlString);
        }

    Now I need to instantiate some values needed by the MOSS service. First we have the “result” object which conveys the state of the copy transaction. Then I have a “FieldInformation” array which can be used to pass in specific field values. Note that you CANNOT pass in a null value here, or else you get a cryptic error when calling the service. You can make it blank, but don’t use a null parameter in its place. Finally, I create a destination Uri array.

    //holds MOSS service response values
    SharePointSvc.CopyResult[] results;
    
    //required fieldinformation array
    SharePointSvc.FieldInformation fieldInfo =
        new SharePointSvc.FieldInformation();
    SharePointSvc.FieldInformation[] fieldInfoArray = { fieldInfo };
    
    //destination url (notice that it's an array, meaning
    //multiple sites COULD be targeted
    string[] destUri = { destinationPath };

    Now I can actually call this puppy. After instantiating the web service proxy class (generated by the Add Web Reference command), I need to provide explicit credentials.

    //create instance of web service proxy
    SharePointSvc.Copy copy = new SharePointSvc.Copy();
    
    //pass valid credentials
    copy.Credentials = new NetworkCredential(userName, password, domain);
    
    //call primary operation;  sourceUri, doesn't matter here
    copy.CopyIntoItems(
         "http://none",
         destUri,
         fieldInfoArray,
         fileIn,
         out results);

    The last step is to actually check the “result” object for errors and return any errors back to the caller.

    //check for error and return final result
    if (results[0].ErrorMessage != null)
      {
        return "Error: " + results[0].ErrorMessage;
      }
      else
      {
        return "Success";
      }

    Sweet.  After building and deploying this service, I can call it from any client, BizTalk (2004/06) included.  I’ll obviously want to securely store my credentials (using Enterprise Single Sign On) and not embed those in my client directly.

    So if I call my service, and pass in a plain old XML file, it shows up in my document library as expected.

    Now, if I send an InfoPath document to a Forms Library set up with an InfoPath template, the result is this …

    Nice! The document is recognized as an InfoPath document (see the icon), and, the promoted columns are properly loaded.

    So, if you’re interested in a fairly easy way to programmatically upload documents to a MOSS 2007 library, without having to use the SharePoint object model or BizTalk adapter, this web service might just work for you.

    Technorati Tags: ,