Passing generics between DAL and WCF
Hi,
I have a solution with layers including wcf. UI calls the WCF.
I am getting an error when calling a List in Service1.svc from the DAL layer. How can I fix it?
Thanks
var client = new ServiceReference1.PizzaAPIClient();
var customer = new ServiceReference1.CustomerAPI();
customer.PhoneNumber = txtPhone.text;
List<ServiceReference1.CustomerAPI> lstcustomers = client.GetCustomerByPhoneNumber(customer);
WCF
IService1.cs
using BL;
namespace WcfService1
[ServiceContract]
public interface IPizzaAPI
// TODO: Add your service operations here
[OperationContract]
List<CustomerAPI> GetCustomerByPhoneNumber(CustomerAPI customer);
[DataContract]
public class OrderAPI
[DataMember]
public string OrderName { get; set; }
[DataContract]
public class CustomerAPI
int _Customerid;
string _firstName;
string _lastName;
string _phonenumber;
public CustomerAPI (int custId, string firstname, string lastName, string phonenumber)
_Customerid = custId;
_lastName = lastName;
_firstName = firstname;
_phonenumber = phonenumber;
[DataMember]
public string PhoneNumber
get { return _phonenumber; }
set { _phonenumber = value; }
[DataMember]
public int CustomerId
get { return _Customerid; }
set { _Customerid = value; }
--omitted for brevity
Service1.svc
using DL;
using BL;
namespace WcfService1
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
public class Service1 : IPizzaAPI
List<CustomerAPI> customerLst = new List<CustomerAPI>();
// Method returning the details of the student for the studentId
public List<CustomerAPI> GetCustomerByPhoneNumber(CustomerAPI customer)
List<CustomerAPI> customerLst = DL.CustomerDB.GetCustomerByPhoneNumber(customer.PhoneNumber); //Error 8 Cannot implicitly convert type 'System.Collections.Generic.List<BL.CustomerBL>' to 'System.Collections.Generic.List<WcfService1.CustomerAPI>'
return customerLst;
CustomerBL.cs -Business Logic Layer
namespace BL
public class CustomerBL
private string phonenumber;
public int CustomerId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public String PhoneNumber
get
return this.phonenumber;
set
this.phonenumber = value;
if (this.PhoneNumber == "")
throw new Exception("Please provide Tel ...");
CustomerDB.cs -DAL layer
using BL;
namespace DL
public static class CustomerDB
public static SqlConnection InitConnection()
DL.ConStrings connstrings = new DL.ConStrings();
return connstrings.GetPizzaDeliveryConnection();
//public static CustomerBL[] GetCustomerByPhoneNumber(string phonenumber)
public static List<CustomerBL> GetCustomerByPhoneNumber(string phonenumber)
SqlConnection connstrings = InitConnection();
using (var connection = connstrings)//using doesn't require connection closed
var cmd = connection.CreateCommand();
cmd.CommandText = "GetCustomerByPhoneNumber";
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@phonenumber", phonenumber);
connection.Open();
var customers = new List<CustomerBL>();
var reader = cmd.ExecuteReader();
while (reader.Read())
var customer = new CustomerBL();
customer.CustomerId = Convert.ToInt32(reader["CustomerId"]);
customer.FirstName = Convert.ToString(reader["FirstName"]);
customer.LastName = Convert.ToString(reader["LastName"]);
customer.Address = Convert.ToString(reader["Address"]);
customers.Add(customer);
return customers;
Hi collie12,
>>Cannot implicitly convert type 'System.Collections.Generic.List<BL.CustomerBL>' to 'System.Collections.Generic.List<WcfService1.CustomerAPI>'
As the error said that we can not simply convert the 'System.Collections.Generic.List<BL.CustomerBL>' to 'System.Collections.Generic.List<WcfService1.CustomerAPI>' by using the following code, because they are different classes:
List<CustomerAPI> customerLst = DL.CustomerDB.GetCustomerByPhoneNumber(customer.PhoneNumber);
Please try to modify the above code as following:
public List<CustomerAPI> GetCustomerByPhoneNumber(CustomerAPI customer)
List<BL.CustomerBL> CustomerBLList= DL.CustomerDB.GetCustomerByPhoneNumber(customer.PhoneNumber);
List<CustomerAPI> CustomerAPIList = new List<CustomerAPI>();
foreach (var CustomerBL in CustomerBLList)
CustomerAPI CustomerAPI = new CustomerAPI(CustomerBL.CustomerId, CustomerBL.FirstName, CustomerBL.LastName, CustomerBL.PhoneNumber);
CustomerAPIList.Add(CustomerAPI);
return CustomerAPIList;
Best Regards,
Amy Peng
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.
Similar Messages
-
Use context to pass value between JPF and Java Control
hi,
Can we use context to pass value between JPF and Java Control? It works if i m using InitialContext in the same machine but i dun think it will works if i put Web server and application server in different machine. Anyone have an idea how to do it?
I also want to get the method name in the onAcquire callback method. Anyone knows how to do this?
thks
?:|Hi.
Yoy can the next options for make this:
1. Pass your values in http request.
example: http://localhost/index.jsp?var1=value1&var2=value2&var3....
2. You can use a no visible frame (of height or width 0) and keep your variables and values there using Javascript, but of this form, single you will be able to check the values in the part client, not in the server. Of this form, the values of vars are not visible from the user in the navigation bar.
Greeting. -
Passing values between jsp and php
hi there, is it possible to pass values between jsp and
php? i really need to find out the way if there is
any. thanks in advance
-azali-Yes, there are a few ways to do this.
1) Think about using Cookies.
2) Maybe use a Redirect passing the values in the Query string.
3) Retain the data in a repository in the back end.
4) Using Hidden fields within your pages.
I am sure you can use these Idea's for a base to develop other methods on how to pass values back and forth from JSP -> PHP and vice versa.
-Richard Burton -
Solution for connection between BODS and WCF web service ?
Hi,
we have a unique requirement of connecting BODS to WCF webservice. This web service acts as a layer for connection between proprietary databases (secured) and other external systems. Queries are to be sent to this web service in order to fetch data from proprietary databases.
In order to connect to these web services, we should also provide Address, Binding and contract whose details are already present with us.
Example of web service address: net.tcp://op12345:10101/sd
I heard Adapters are the best way of connecting to the above web service, could you please provide some guidance on connecting through adapters if it is the best solution.
Could someone suggest the best possible approach(ASAP) to bring connection between BODS and web services and to execute the above requirement.
Please let me know in case of any more information.
Regards
SuryaHello Nir,
I tried to import the my VS2008 + .net 3.5 as Wsdl local file to the Xcelsius 2008 but there is message unable to load url.
I tried to import your Wsdl developed by .net:
http://www.webservicex.net/airport.asmx?WSDL
and it works ok.
Can you send me or print here the service class definition and the configuration file for http://www.webservicex.net/airport.asmx?WSDL?
Thanks in advance,
Sergey Osmachkin -
How to pass data between JDialog and its parent window ?
Hi,
I am new to swing. I want to know how pass data between a JDialog and its parent window.
If you have any information please reply with example code.
Thank Youhi Encephalopathic ,
I was looking for something like as it was given in the link provided by you.
Thank you for reply It really helped me. -
Hello All,
I am working with the following example (from previous postings on this
board) that demonstrates how to run a sub vi in parallel with the main
vi. I'd like to pass parameters between the main and sub such as
the control (delay) and indicator (value) parameters of my subvi
example. Does any one know how to do this? Parallel
execution is important for me, I cannot just paste the subvi icon into
my main diagram (two nested while loops...)
Many thanks,
Luis
Message Edited by cascao on 08-16-2005 08:42 PM
Message Edited by cascao on 08-16-2005 08:42 PM
Attachments:
VI_Server_technique.vi 32 KB
SubVI_1.vi 19 KBcascao wrote:
Hello All,
I am working with the following example (from previous postings on this
board) that demonstrates how to run a sub vi in parallel with the main
vi. I'd like to pass parameters between the main and sub such as
the control (delay) and indicator (value) parameters of my subvi
example. Does any one know how to do this? Parallel
execution is important for me, I cannot just paste the subvi icon into
my main diagram (two nested while loops...)
Many thanks,
Luis
Luis, you can use the VI Server methods 'Set Control Value' and 'Get Control Value', as demonstrated in the attached examples.
-Franz
Attachments:
VI Server.zip 26 KB -
Passing attributes between providers and portlets
When using Providers, it is possible to pass session data between providers via ProviderContext.setSessionProperty. Is it possible to pass attributes from a provider to a portlet? Anything set on the ProviderContext does not seem to get propagated to the portlet via PortletSession.getAttribute(). Similarly the attributes set on the provider's request object to not seem to be propagated to the PortletRequest.
My understanding is that Providers are the Sun proprietary portal technology, predating JSR 168 and Portlets.
You can use Portlets to implement leaf channels ... but you must still write Providers if you want to fiddle with containers. -
Passing parameters between JSP and Servlet
The scenario is as follows:
There is a JSP page that sends a string as a hidden parameter to a servlet:
<input type="hidden" name=<%= Book.NAME %> value=<%= book.getName() %> >
In the servlet there is a print statement that checks the parameter value:
System.out.println("Book name: "+request.getParameter(Book.NAME));
The problem is as follows: if the name of the book consists of more than one word
such as "Servlets and JSP", the print statement will print only Servlet.
If the JSP page passes a string directly as shown here:
<input type="hidden" name="Test" value="Test String" >
The servlet will print the complete string: Test String
The same problem appears if the string is passed between two JSP pages.
Any help is greatly appreciated.
Regards,
Basil MahdiYou might want to try
<input type="hidden" name="<%= Book.NAME %>" value="<%=URLEncode.encode(book.getName(), "UTF-8")%>" >This will take care of any wierd un-url friendly charcters that might appear in the book titles such as the ' or " which may be the problem. -
Passing parameter between jpanel and jframe
Hi guys,
First time posting, so please be nice! :p
Basically, the problem i'm having:
I have created a JFrame class, which adds some JPanels to itself to start with (basic layout stuff).
This JFrame is created and instantiated in main.java, and just displays the basic stuff that i've added.
On the JFrame are a number of JButtons, and when you click on the JButton each JButton it adds a custom JPanel to the main JFrame. Basically, it provides an easy way to produce a kind of menu system using the JPanels.
The problem i have, is that each time a textbox is clicked inside one of the custom JPanels, i want it to pass the name of the textbox and jpanel back to a method setLastTextBox() in the JFrame class.
I tried:
private void jTextPane1FocusGained(java.awt.event.FocusEvent evt) {
super.setLastTextBox()
}But super. is not the correct call. I'm sure its something pretty simple but i can't think what it is, and i tried googling it to no avail.
I would be extremely greatful if someone could put me back on the right path!
Thanks,
--MarkHi, Mark
I hope I understood you rihgt.
I think that you should add Focus Listeners to the text boxes, rather than panels and create a method setLastTextBox(String panelName, String textBoxName)
and just write something like that
textField1.addFocusListener(new FocusAdapter(){
public void focusGained(FocusEvent e) {
String textFieldName = ((JTextField)e.getSource()).getName();
String panelName = ((JTextField)e.getSource()).getParent().getName();
setLastTextBox(textFieldName, panelName);
}); that is if you write this code inside your frame class
otherwise you can get to your frame, by calling the method getParent() and checking its class until its not YourFrameClass (or JFrame) and then just cast it and call the method.
I hope I was clear
Ksenia -
Pass Object Between Applet and JSP Page
Hi all,
How can I pass an Object(such as Vector, File), rather than just string to the Applet from a JSP page?
Thank you.I used Base64Encoder and Base64Decoder from servlets.com utilities.
* convert any serializable object to a String
public synchronized static String objectToString(Serializable obj) throws Exception {
ByteArrayOutputStream bos = new ByteArrayOutputStream(100);
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(obj);
byte[]bytes = bos.toByteArray();
bos = new ByteArrayOutputStream(); //to save the encoded String
Base64Encoder enc = new Base64Encoder(bos);
enc.write(bytes);
String encodedString = bos.toString();
//close all
enc.close();
oos.close();
bos.close();
return encodedString;
* Recreates the object from the encoded String
public synchronized static Object stringToObject(String str) throws Exception {
ByteArrayInputStream bis = new ByteArrayInputStream(str.getBytes());
Base64Decoder dec = new Base64Decoder(bis);
ObjectInputStream ois = new ObjectInputStream(dec);
Object obj = (Object)ois.readObject();
ois.close();
dec.close();
bis.close();
return obj;
} -
Passing Parameters between Portal and Forms 6i
Hi,I'm new in Oracle Portal and I have a problem. I have a Portal's report and I need to pass a value from this report to Form 6i to perform the query. This form is a porlet including in the Portal page.
please help meHi, Im trying to do that you said, but doesn't work :-(, my code is something like this, in the portlet.xml(jboss portal 2.6) :
<portlet-preferences>
<preference>
<name>stockSymbols</name>
<value>BEAS</value>
</preference>
<preference>
<name>refreshInterval</name>
<value>600</value>
</preference>
</portlet-preferences>
in the consumer(bea wlp 8.1 sp5), i dont see any portlet preference in the palette window, im doing something wrong?...thanks for your help. -
Passing parameters between server and client side
Dear All
I writing a server-side web service and using wsdl to expose its methods for a 'client' to use.
However, i need to make sre the clients creates a soap header? How can i tell the client it must create a soap header?
Also can someone tel me how i pass a value from the server-side to the client-side and also get a vlue from the client soap message
Many thanksIn your wsdl you would have the header as part of the input for example, see the operation below:
<wsdl:operation name="foo">
<soap:operation soapAction="http://www.foobar.com/foo" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
<soap:header message="tns:FooSoapHeader" part="MySoapHeader" use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation> -
Passing objects between Servlets and JSP
Hi,
I have passed a ResultSet from a Servlet to JSP using RequestDispatcher forward(). I can access the ResultSet in the JSP page. How can I now pass this ResultSet into another JSP page once the form has been submitted?
Thanks in advance.You should never passing expensive resources like ResultSet around like that. This indicate an open DB connection somewhere while it should already be closed at this stage.
Read on about the DAO pattern and make use of servlets and beans. -
Pass data between AS and Lingo
Hi
We have an Arabic educational application in Director 11.5, published originally asprojector for desktop use. Since Director don't support “right to left” languages, the application uses an ActivX component to call external encoded html and load it into a textarea container, in this way the Arabic language can be written and redden.
since ActiveX is not sockwave-safe and cannot be used , im using swf as an input textarea. it seems ok ( i dont read Arabic so i cant tell if its correct), the important thing for this stage is that i can write text and no errors comes from the shockwave player.
The main problem:
the words been typed in the swf , should be sent to the the Lingo script in Director, for example there is a "speed typing test " that check if all the typed words are correct.
in the original the application uses:
sprite(120).navigate(the moviePath & "assets\t.html")
to load the html into the textarea and uses and:
on hideQuitDialog me
if the frame > 45 then
mySprite.locV = 485
mySprite.puppet = 0
mySprite.navigate("Javascript: focusText()")
end if
end
to get some javascript from the html.
my question is how to pass the swf input data to Lingo? what code should i use, either in Flash AC3 or in Lingo in Director to make this happand?
appreciate you time
Tx
ShayHi,
The problem was that when populating and reading the custom controller, I had to add GLOBAL. in front of the custom controller name. Like this: 'GLOBAL.ZKBT116QH_SRVQ/CuCoOrders'
Thank you,
Andra. -
Pass Data between flex and livecycle
Hi ,
I am unable to downlaod a file from the server using flex's
filereference.download api .
Attached simple program to pass/upload a file to livecycle
server and convert it to a pdf. The livecycle process returns the
file.
My flex application downloads the file however, the file
content is just 1 kb. The content seems to be the filepath in the
server (e.g. c:\tmp\TestDoc[3].pdf).
The livecycle process takes inDoc and fileName as parameter
and returns outDoc and fileName.
any help would be greatly appreciated.
Please find attached sourceCode.Hi,
The problem was that when populating and reading the custom controller, I had to add GLOBAL. in front of the custom controller name. Like this: 'GLOBAL.ZKBT116QH_SRVQ/CuCoOrders'
Thank you,
Andra.
Maybe you are looking for
-
Client Install Issue - SCCM 2012 R2 - Manual Deploy Installed ok
Hello, I have sccm 2012 configured with 2,000 machine approx. It is been used mainly as a Software Deployment tool for now. On checking a recent IE10 upgrade, I noticed that there is a number of machines that do not have the client installed (and thu
-
J2ee Admin User locked on SDM Deployment - BI 7.0 and EP 7.0
Hi, We had a recent issue on BI iview publishing from the BEX WAD 7.0 in our Production Portal server. The BEX WAD had the error " Java communication error" " An Error occured during communication with the BI Components of the J2ee engine" We traced
-
I have a Macbook from 2007 or earlier. I currently run OSx 10.6.8. I wanted to upgrade to Mavericks so that I can get the new aperature. However I was wondering if my Macbook model was to old to run mavericks. Is this the case? Do i need a newer
-
Problema de compatibilidad de adobe photodeluxe home edition 3.0 con windows xp
Alguien me podria decir que puedo hacer para poder usar photodeluxe home edition en windows xp ya me he bajado los parches pero al ejecutarlos me dice que tampoco son compatibles os agradeceria vuestra respuesta. mi mail es [email protected] . respon
-
This problem has been driving me nuts, however I came across what I think is the answer. I have CS4 and Windows Vista. If I have CS4 open and then open Bridge and right click on an thumbnail in Bridge and select 'open in ACR', or 'control+R', then th