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
Related
I am in the progress of rewriting some code to work with ASP 5.
The old code does the following:
string Local_IP=Request.ServerVariables["LOCAL_ADDR"];
string HTTP_reverse_VIA = Request.ServerVariables["HTTP_REVERSE_VIA"];
How do I get the corresponding information from ASP 5?
HttpContext has the GetFeature method, using this method we can get feature information.
Here we are want to get Server Variables of IIS; check project.json "Microsoft.AspNet.Server.IIS" is used for running ASP.NET 5.
We have to use GetFeature of 'Microsoft.AspNet.Server.IIS' which contains Server variables feature. use the below code
var varibleFeature = Context.GetFeature<Microsoft.AspNet.Server.IIS.Features.IServerVariablesFeature>();
if (varibleFeature != null)
{
var valuesList = varibleFeature.ServerVariables;
//read through valuesList dictionary for Server Variables
}
Since I was running on IIS Express, it gave few variables but not the one mentioned in your question.
Please deploy it on IIS and explore more.
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).
I'm new to Silverlight. My code works in Window Forms:
static void Main()
{
DBConnect dbconnect = new DBConnect();
using (System.IO.StreamWriter file = new System.IO.StreamWriter(#"C:\Temp\WriteLines4.txt", true))
{
file.WriteLine(dbconnect.CountPublic());
}
dbconnect.CloseConnectionPublic();
}
It connects to database, counts rows in table, writes result into txt file and closes connection.
Now my need is to show result in silverlight (web page) instead of writing into txt file. How do I start?
UPDATE:
Silverlight doesn't work with database directly. My need is to create WCF service for work with database and consume service using Silverlight.
Found simple example for SL & WCF to start with:
http://sonyarouje.com/2010/10/16/image-uploading-retrieving-silverlight-and-wcf/
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.
I currently have a simple WCF service with the following operation:
[OperationContract]
int InsertApplication(Application application);
The Application Parameter is defined as follows:
[DataContract]
public class Application
{
int test = 0;
[DataMember]
public int Test
{
get { return test; }
set { test = value; }
}
}
This service is being consumed within a Windows service with a namespace SpringstoneColoAgent. I added a service reference with no problems called OfficeInternalService. The code that calls the service method is as follows:
Application application = new Application();//= ConvertToApp(app);
application.Test = 1;
int oracleID = client.InsertApplication(application);
However, visual studio is telling me that 'application' is an invalid parameter. On further research I try to build anyway. I get a bunch of errors pointing to the Reference.cs file. Looking at this file I determine all the errors revolve around code that uses the following:
SpringstoneColoAgent.OfficeInternalService._
Where anything it is trying to reference under the service reference name is incorrect. So for example this code is giving an error:
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IOfficeInternalService/InsertApplication", ReplyAction="http://tempuri.org/IOfficeInternalService/InsertApplicationResponse")]
int InsertApplication(SpringstoneColoAgent.OfficeInternalService.Application application);
If I do not fully qualify the namespace and remove SpringstoneColoAgent.OfficeInternalService. so that the code looks like this:
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IOfficeInternalService/InsertApplication", ReplyAction="http://tempuri.org/IOfficeInternalService/InsertApplicationResponse")]
int InsertApplication(Application application);
This will fix the error. I repeated this everywhere I could find the error and everything compiled fine. The downside is that everytime I make a change to the WCF service and need to update the service reference it loses these changes and I have to go back and change them.
I'm guessing I am missing something here and was curious if anyone had any direction or has run into a similar situation.
Thanks for any advice!
The Application class is a known .NET type: http://msdn.microsoft.com/en-us/library/system.windows.forms.application.aspx. Try to work with a different class name to avoid name clashes.
Also try to avoid the int private member in the datacontract. Because it is not a datamember, it is not exposed in the WSDL and a generated proxy class on the client side does not know this private member. This can also cause problems.