How can I "wrap" a Linq2Sql data context in a webservice? - web-services

Relevants: Visual Studio 2010,
WCF WebServices,
Linq2Sql,
.Net 4.0
Forgive me if this is a stupid question, but I believe I have seen something similar to what I'm trying to do.
We have a Linq2Sql data context we are using to read/write to a database. We'd like to expose a public API to the database for certain vendors. I seem to recall a way to expose most of the data context functionality through a web service without creating wrappers for all the CRUD methods manually. Anybody out there know how to do this? I seem to remember seing the data context exposed through a web service with just a few lines of code.
We would also need to deny access to some methods, based on permissions, but can probably work through that ourselves.

Not sure what you saw or refer to... but WCF Data Services seem to be what you are after - check them out at http://msdn.microsoft.com/en-us/data/bb931106.aspx

#Yahia got me pointed in the right direction. This article is nearly what I was looking for, but deals with ADO.Net Entity Data Models rather than LINQ data contexts. Very nearly there...
Data Access with ADO.Net Data Services.
So, it turns out the answer is pretty simple.
Create a new ASP.Net web application.
Right-click the web application.
Add --> New Item --> WCF Data Service.
Modify the code to support your context:
using System.Data.Services;
using System.Data.Services.Common;
namespace DelvingWare.Data.FilestreamServer.WebServices
{
public class WcfDataService1 : DataService<MyDataContext>
{
// This method is called only once to initialize service-wide policies.
public static void InitializeService(DataServiceConfiguration config)
{
// TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
// Examples:
config.SetEntitySetAccessRule("MyEntitySet", EntitySetRights.ReadSingle);
config.SetServiceOperationAccessRule("MyEntitySet", ServiceOperationRights.ReadSingle);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
}
}
}
Build --> Right Click Service --> View In Browser. Voila!

Related

WebService Task in Camunda

In Camunda BPM designer, I couldn't find activity and for invoking a REST or SOAP based webservices. Is it only possible to invoke through wiring code? How do I pass payload to the code if it needs to be written using java code.
Regards,
Phani
You can invoke a Webservice inside a bpmn.
You can create a Task of type Service, and choose in Properties/Details/Implementation: Connector.
Next you configure Connector properties, setting:
Connector Id: http-connector (for rest json webservices) and
Input Parameters:
url (e.g. http://localhost:8080/client?id=12
method GET/POST
headers type MAP: Accept application/json...
You receive the webservice response as Process Variables, configuring the Output parameters as follows :
response, type text, value ${response}
returnCode, type text, value ${statusCode}
Hope this helps you
For start: please note that camundas claim is "developer friendly". It's never been the goal of camunda components to just "click together" a working process. If you are looking for such a solution, you should a) have a look at the zero coding myth and b) maybe choose another tool.
That being said, check out the camunda-connect framework, introduced with 7.2, it should do what you need (though it involves xml coding).
For all but the most simple SOAP / REST calls, you'll need to go through java code. This takes a little getting used to when moving from other BPM platforms with extensive built-in webservice support. But trust me, java code is the way to go - import of transform / WSDL in the process definiton becomes such a holy mess.
I've written two CXF-based examples: soap-cxf-service and soap-cxf-server-start which will get you started.
I recommend creating a maven artifact per webservice and just adding the required services as standard maven dependencies for your process project.

SSIS package: How to insert/update data into a Sql server's table by calling a web service in a ssis package?

Is there any way to call a web service in a ssis package in order to insert some data into a table within SQL Server? How? any sample or guidance please?
I assume by your question, you are referring to using a web service as a destination for a data flow? I inherited a series of packages that integrate with our MS CRM site. As designed, these packages are a horrible fit for the SSIS paradigm but that's my burden to bear...
These packages generally fit the form of Source (OLE DB or Flat File) fed to a Script Task (destination). I don't know that providing all the code of a particular task would be enlightening. It's simply invokes the web service for each row sent into it. RBAR is not what SSIS or set based languages are made for but you can certainly do it.
The Script transformation will have a web reference (ours is named CrmSdk) to the service.
Declare an instance of the service as a member of ScriptMain.
Instantiate that service in your script, passing credentials as needed. Most likely in your PreExecute method
Make calls to the web service in your Input0_ProcessInputRow method using the Row.Column1 notation. Do be aware of nulls and how the web service handles them. Our code uses service.CompanyName = Row.CompanyName_IsNull ? string.Empty : Row.CompanyName;
If your intention is to use a web service at the Control Flow level, be aware that the default Task has a hard coded 5 minute timeout. Not sure if that's still the case, but in the 2005 package I was dealing with, we had to use a straight Script Task to communicate with our webservice (it was cleansing millions of rows of address data in batch fashion) to bypass the timeout issue. Reference to timeout property

How do you configure WorkManagers in WebLogic 10.3?

I would like to use a WorkManager to schedule some parallel jobs on a WebLogic 10.3 app server.
http://java.sun.com/javaee/5/docs/api/javax/resource/spi/work/WorkManager.html
I'm finding the Oracle/BEA documentation a bit fragmented and hard to follow and it does not have good examples for using WorkManagers from EJB 3.0.
Specifically, I'd like to know:
1) What exactly, if anything, do I need to put in my deployment descriptors (ejb-jar.xml and friends)?
2) I'd like to use the #Resource annotation to inject the WorkManager into my EJB 3 session bean. What "name" do I use for the resource?
3) How do I configure the number of threads and other parameters for the WorkManager.
My understanding is that the underlying implementation on WebLogic is CommonJ, but I'd prefer to use a non-proprietary approach if possible.
First, you'll find the documentation of CommonJ, an implementation of the Timer and Work Manager API developed by BEA Oracle and IBM, in Timer and Work Manager API (CommonJ) Programmer’s Guide. They provide a Work Manager Example but it's not injected in this document.
1) What exactly, if anything, do I need to put in my deployment descriptors (ejb-jar.xml and friends)?
According to the Work Manager Deployment section:
Work Managers are defined at the
server level via a resource-ref in the
appropriate deployment descriptor.
This can be web.xml or ejb-jar.xml
among others.
The following deployment descriptor
fragment demonstrates how to configure
a WorkManager:
...
<resource-ref>
<res-ref-name>wm/MyWorkManager</res-ref-name>
<res-type>commonj.work.WorkManager</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
...
Note: The recommended prefix for the JNDI namespace for WorkManager
objects is java:comp/env/wm.
Check the WorkManager javadocs for more details (e.g. "The res-auth and res-sharing scopes are ignored in this version of the specification. The EJB or servlet can then use the WorkManager as it needs to.").
2) I'd like to use the #Resource annotation to inject the WorkManager into my EJB 3 session bean. What "name" do I use for the resource?
I'd say something like this (not tested):
#ResourceRef(jndiName="java:comp/env/wm/MyWorkManager",
auth=ResourceRef.Auth.CONTAINER,
type="commonj.work.WorkManager",
name="MyWorkManager")
3) How do I configure the number of threads and other parameters for the WorkManager.
See the description of the <work-manager> element and Using Work Managers to Optimize Scheduled Work for detailed information on Work Managers
My understanding is that the underlying implementation on WebLogic is CommonJ, but I'd prefer to use a non-proprietary approach if possible.
I don't have any other suggestion (and, as long as this implementation follows the standards, I wouldn't mind using it).
The Weblogic documentation will answer your questions.
Using Work Managers to Optimize Scheduled Work

BizTalk WMI Remote Wrapper

I'm using MgmtClassGen.exe from the .Net Framework SDK to generate some WMI wrapper classes for BizTalk artifacts like hosts, host instances, etc.
I'm using HostSetting.GetInstances() to get the local hosts (local BizTalk Server). This works fine. I'm now looking for a way to do the same for hosts on another BizTalk machine with a different BizTalk management database name. I can't find a way to do this using the wrapper classes. I do want the wrapper classes. Any idea how to connect to BizTalk Management database with name 'MyManagementDB' on server 'ServerX'?
Thanks in advance!
You can choose a different server to connect to by specifying it in the WMI scope declaration.
In your code you will have something like the following:
ManagementClass objHostSettingClass = new ManagementClass("root\\MicrosoftBizTalkServer", "MSBTS_HostSetting", null);
The first parameter in the constructor call there is the scope. This can include a server name as shown below:
ManagementClass objHostSettingClass = new ManagementClass("\\\\ServerX\\root\\MicrosoftBizTalkServer", "MSBTS_HostSetting", null);
I don't believe that you will need to know the message box name - the WMI MicrosoftBizTalkServer provider should let you access the host instances on the server directly.
EDIT
As Maxime points out in the comment below, there is a way of setting the WMI scope that more integrated with the code generated by the MgmtClassGen.exe tool.
This allows you to set the StaticScope property of the generated classes. This still involves building a string defining the scope but gives a single place to define it. Maxime has a nice post defining a helper class that builds the StaticScope string.
I know this could be considered off topic since you are somewhat asking specifically of WMI, but there is also a .NET library that provides access to all of the BizTalk artifacts called Microsoft.BizTalk.ExplorerOM.dll. I used it to turn on/off receive locations in a small C# app. Here is a link to my previous Stack Overflow question with more information:
Is there a way to automate turning a BizTalk Receive Location on or off through code?
Just another option for altering or administrating BizTalk artifacts through code.

Automate test of web service communication

I have an application that sends messages to an external web service. I build and deploy this application using MSBuild and Cruisecontrol.NET. As CCNET build and deploys the app it also runs a set of test using NUnit. I'd now like to test the web service communication as well.
My idea is that as part of the build process a web service should be generated (based on the external web services WSDL) and deployed to the build servers local web server. All the web service should do is to receive the message and place it on the file system so I then can check it using ordinary NUnit for example. This would also make development easier as new developers would only have to run the build script and be up and running (not have to spend time to set up a connection to the third party service).
Are there any existing utilities out there that easily mock a web service based on a WSDL? Anyone done something similar using MSBuild?
Are there other ways of testing this scenario?
I just started looking into http://www.soapui.org/ and it seems like it will work nicely for testing web services.
Also, maybe look at adding an abstraction layer in your web service, each service call would directly call a testable method (outside of the web scope)? I just did this with a bigger project I'm working on, and it's testability is working nicely.
In general, a very good way to test things like this is to use mock objects.
At work, we use the product TypeMock to test things like Web Service communication and other outside dependencies. It costs money, so for that reason it may not be suitable for your needs, but I think it's a fantastic product. I can tell you from personal experience that it integrates very well with NUnit and CCNet.
It's got a really simple syntax where you basically say "when this method/property is called, I want you to return this value instead." It's great for testing things like network failures, files not being present, and of course, web services.
Take a look at NMock2. It's a open-source mocking product and allows you to create "virtual" implementations for interfaces that support rich and deep interaction.
For example, if your WS interface is called IService and has a Data GetData() method, you can create a mock that requires the method to be called once and returns a new Data object:
var testService = mockery.NewMock<IService>();
Expect
.Once
.On(testService)
.Method("GetService")
.WithNoArguments()
.Will(
Return.Value(new Data());
At the end of the test, call mockery.VerifyAllExpectationsHaveBeenMet() to assure that the GetData method was actually called.
P.S.: don't confuse the "NMock2" project with the "NMock RC2", which is also called "nmock2" on sourceforge. NMock2-the-project seems to have superseded NMock.
This might also be something - MockingBird. Look useful.
At my work place we are using Typemock and nUnit for our unit testing.