silverlight datapager and stored procedure - silverlight-4.0

Is there a way using standard datapager (bound to DomainDataSource) on the server side get the current page (so that to pass it to stored procedure)? Silverlight 4.0, 2010 aprils toolkit, ria service.

I've found one: in your LinqToEntitiesDomainService class override public override
System.Collections.IEnumerable Query(QueryDescription queryDescription, out IEnumerable<ValidationResult> validationErrors, out int totalCount)
Then extract take and skip from queryDescription.Query.ToString() and return this.ObjectContext.YourStoredProcedure(with paging params).
However, you'll have to handle sorting manually too (sigh).

Related

Call Worklight Javascript SQL Adapter form REST Client

I am using IBM Worklight 7.1 and I am trying to call a Javascript SQL adapter form REST client like HttpRequester. I can call adapter but cannot figure out how to pass parameters to procedure.
For Adapter named MyAdapter and procedure named myProc, I can call adapter using baseUrl/MyAdapter/myProc, using both GET and POST method form REST Client, but all the parameters in procedure are undefined.
function myProc(a,c) {
return {
result : "OK"
};
}
I have tried passing parameter in following ways.
As query string ?a=b&c=d
As JSON String {"a":"b","c":"d"}
Passing parameter in array as parameters=['b','c']
Why Do This
Reason behind doing this is to make Data Setting, Procedure call, Output check and data erase process automatic by writing script to make testing easy and automatic. So, feel free to suggest if any other better process already exist to do above steps automatically.
When calling a JavaScript adapter (this answer is not applicable to Java adapters), the REST call should look like:
/{project-context}/adapters/{adapter-name}/{procedure-name}/?params=[a,b,c,d]
In other words, a JavaScript procedure receives only ONE parameter called params which needs to be an array of ordered, unnamed values.

WCF service with 4 input parms and 3 out parms gets reordered by Add Service Reference in Proxy Class Project

I've looked in SO and elsewhere and seen questions posed about this along with some answers that still make no sense to me in my case.
I'm refactoring my working VStudio 2010 solution which has:
one project with an ASMX webservice
another separate project for the proxy class (no code here except what is generated by Add Web Reference
another separate project for the client (contains a reference to the
ProxyClass.dll
The new VStudio 2010 solution has:
one project of type WCF service library for the contract by itself (IFileService.cs)
one project of type WCF service library for the implementation of the contract (FileService.cs)
another separate project for the proxy class (no code here except what is generated by Add Service Reference
another separate project for the client (contains a reference to the WCFProxyClass.dll)
Here is the contract which ends with 3 out parameters (and the implementation of same is the same order):
[ServiceContract(Name = "IFileService", Namespace = "http://www.cbmiweb.com/TrimWCF/2011/11")]
public interface IFileService
{
[OperationContract]
public string DownloadFile(string trimURL
, string TrimRecordNumber
, string CallerPC
, string RequestorID
, out byte[] docContents
, out string returnFiletype
, out string returnFilename)
{
Here is what Add Service Reference generated in my proxy class project:
public string DownloadFile(
out byte[] docContents
, out string returnFiletype
, out string returnFilename
, string trimURL
, string TrimRecordNumber
, string CallerPC
, string RequestorID)
{
return base.Channel.DownloadFile(out docContents, out returnFiletype, out returnFilename, trimURL, TrimRecordNumber, CallerPC, RequestorID);
}
I have read answers ranging from "you cannot use out parms in WCF" to "you should not use Add Service Reference but instead use svcutil.exe" to "the order of the parameters do not matter...it will still work".
I am confused about what to do here (and what I've done wrong that led to this re-arranged order and WHY that happened).
First of all, you haven't done anything wrong :). Even though the signatures in the methods in the client and the server are different, they're equivalent wrt the messages which will be produced / consumed by them. You can use that proxy class without any problems, and it should work just as well.
Why this happens is another story - in the service description (WSDL), there are two "messages" for each (non-one-way) operation: one with the input parameters, one with the output parameters. The messages contains respectively the input(s) and output(s) of the operation, but there's nothing in the WSDL which shows the order of them. So when a tool such as Add Service Reference or svcutil is generating the client proxy, it will simply "choose" one order (out parameters first), but the request which the proxy will send to the service will be compatible with what the server expects (and also, the response from the server will be correctly understood by the proxy).
If you want to maintain the order of the parameters, you can create the proxy class yourself. For this you can either use the ChannelFactory<T> class, or create your own client class derived from ChannelBase<T>. But you don't really need to do that, as I mentioned before.

Calling a WCF DataService [WebGet] function from the client

I have an EF4 model with a stored procedure that I want to call from the client.
The server code looks like this:
[WebGet]
public IQueryable<SalesData> GetSalesReport(int reportType, int yr, int m, int d)
{
DateTime dt = new DateTime(yr, m, d);
return this.CurrentDataSource.RP_SalesReport(reportType, dt, dt).AsQueryable<SalesData>();
}
When calling this using IE using the URL "http://localhost:12345/MyService.svc/GetSalesReport?reportType=1&yr=2009&m=4&d=2" it works as expected.
In my client application I added a reference to the Service (http://localhost:12345/MyService.svc) and whetever I have tried, the function "GetSalesReport" does not show up in the object browser.
(Normal EF entities does show up in the object browser)
So my question is: How do I call this function from the Client ?
And is there a difference on how to call this function depending on the client (I want to call this function from a Windows Phone 7 Silverlight App, but right now I am testing using a WPF test client).
Actually it looks like the ADO.NET DataTeam hasn't implemented CodeGen for calling a ServiceMethod from the client.
So the soloution to my problem is to write this code at the client:
// execute the service operation
Uri u = new Uri(string.Format("{0}/GetSalesReport?reportType={1}&yr={2}&m={3}&d={4}",
context.BaseUri, 1, 2009, 4, 2),UriKind.RelativeOrAbsolute);
var datas = context.Execute<SalesData>(u);
Thanks to Gil Fink that wrote this Blog post: http://blogs.microsoft.co.il/blogs/gilf/archive/2008/11/14/consuming-data-services-service-operations.aspx

Consume WCF Data service in client application throws error

I am working on WCF Data service which imported stored procedure, as below.
[WebGet]
public List<GetMTSearchResultTest_Result> GettMTSearchResultTest()
{
MediaMarketResearch_PRODEntities ent = new MediaMarketResearch_PRODEntities();
return ent.GetMTSearchResultTest().ToList();
}
when i consuming this in my client application it says error as "The closed type MMRClient.MMRServiceReference.GetMTSearchResultTest_Result does not have a corresponding element settable property."
I am getting this error while bind to the grid view as below.
DataServiceContext context = new DataServiceContext(new Uri("http://localhost:4131/MMRDataService.svc/"));
IEnumerable<GetMTSearchResultTest_Result> empResult = context.Execute<GetMTSearchResultTest_Result>(new Uri("http://localhost:4131/MMRDataService.svc/GettMTSearchResultTest"));
GridView1.DataSource = empResult;
GridView1.DataBind();
Note: I imported this stored proc as complex type.
Please advice me on this.
Regards,
Jaydeep
I think this link may help you (see the selected answer).
Essentially, what the solution may be is to create a partial class for GetMTSearchResultTest_Result and decorate it with a DataServiceKey attribute, providing a non-nullable column that acts as a primary key (although I don't think it has to be unique).
So your partial class would look something like:
[DataServiceKey("YourKeyColumnName")]
public partial class GetMTSearchResultTest_Result {
}
If you're just doing reads, I don't think you'll need any implementation.
Hopefully this works. Let me know if there are issues/questions and I'll update accordingly.
You can always make a new service reference to a non data service. That is to a normal WCF service. You can simply have a [ContractOperation] returning a list of the troubled "complex types" and that's it.
This way you would have two services the original data service and a new normal WCF service. But this shouldn't be such an issue. You don't have to make the troubled "complex type" as a Entity.

SessionFactory - one factory for multiple databases

We have a situation where we have multiple databases with identical schema, but different data in each. We're creating a single session factory to handle this.
The problem is that we don't know which database we'll connect to until runtime, when we can provide that. But on startup to get the factory build, we need to connect to a database with that schema. We currently do this by creating the schema in an known location and using that, but we'd like to remove that requirement.
I haven't been able to find a way to create the session factory without specifying a connection. We don't expect to be able to use the OpenSession method with no parameters, and that's ok.
Any ideas?
Thanks
Andy
Either implement your own IConnectionProvider or pass your own connection to ISessionFactory.OpenSession(IDbConnection) (but read the method's comments about connection tracking)
The solution we came up with was to create a class which manages this for us. The class can use some information in the method call to do some routing logic to figure out where the database is, and then call OpenSession passing the connection string.
You could also use the great NuGet package from brady gaster for this. I made my own implementation from his NHQS package and it works very well.
You can find it here:
http://www.bradygaster.com/Tags/nhqs
good luck!
Came across this and thought Id add my solution for future readers which is basically what Mauricio Scheffer has suggested which encapsulates the 'switching' of CS and provides single point of management (I like this better than having to pass into each session call, less to 'miss' and go wrong).
I obtain the connecitonstring during authentication of the client and set on the context then, using the following IConnectinProvider implementation, set that value for the CS whenever a session is opened:
/// <summary>
/// Provides ability to switch connection strings of an NHibernate Session Factory (use same factory for multiple, dynamically specified, database connections)
/// </summary>
public class DynamicDriverConnectionProvider : DriverConnectionProvider, IConnectionProvider
{
protected override string ConnectionString
{
get
{
var cxnObj = IsWebContext ?
HttpContext.Current.Items["RequestConnectionString"]:
System.Runtime.Remoting.Messaging.CallContext.GetData("RequestConnectionString");
if (cxnObj != null)
return cxnObj.ToString();
//catch on app startup when there is not request connection string yet set
return base.ConnectionString;
}
}
private static bool IsWebContext
{
get { return (HttpContext.Current != null); }
}
}
Then wire it in during NHConfig:
var configuration = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2005
.Provider<DynamicDriverConnectionProvider>() //Like so