I have created a database with details of a car. I have to test the database using the WCF Test client. Once I input a car ID and invoke, it will not display my data from the table. Only null values. Here is my code for the service class. Why will my saved data from my table not display?
public class CarService : ICarService
{
public Car GetCar(int id)
{
CarBDO carBDO = new CarBDO();
Car car = new Car();
TranslateCarBDOToCarDTO(carBDO, car);
return car;
}
private void TranslateCarBDOToCarDTO(CarBDO carBDO, Car car)
{
car.CarID = carBDO.CarID;
car.CurrentOwner = carBDO.CurrentOwner;
car.DateFirstRegistered = carBDO.DateFirstRegistered;
car.SornStatus = carBDO.SornStatus;
car.Colour = carBDO.Colour;
car.EngineSize = carBDO.EngineSize;
car.YearofManufacture = carBDO.YearofManufacture;
car.DateTaxed = carBDO.DateTaxed;
car.Make = carBDO.Make;
car.Model = carBDO.Model;
}
I'm using wcf test client in order to test my web services. I'm pretty sure its not about wcf test client. for troubleshooting i suggest to log the values and see if they are actually null or not. then post the more detail so we can help you.
Related
How to set Custom Menu Field values in Rightnow API of Oracle ?
I have a Custom field of data type Menu like :
Custom field Name : user type
Data Type : Menu
Value can be : Free, Paid or Premium
Can any one send me the java code by solving this problem?
Thanks in Advance
The following link is from the Oracle Service Cloud developer documentation. It has an example of setting a contact custom field using Java and Axis2, which would likely give you most of the information that you need in order to set your custom field.
At a high level, you must create an Incident object and specific the ID of the incident that you want to update. Then, you must create the custom field object structure using generic objects (because each site can have its own unique custom fields). Ultimately, your SOAP envelope will contain the node structure that you build through your java code. Since you're trying to set a menu, the end result is that your custom field is a NamedID object. You'll set the lookup name of the menu to one of the three values that you give above.
I'm a C# guy myself, so my example is in C#, but it should be easy to port to Java using the link above as an example too.
public static void SetMenuTest()
{
Incident incident = new Incident();
incident.ID = new ID();
incident.ID.id = 1234;
incident.ID.idSpecified = true;
GenericField customField = new GenericField();
customField.name = "user_type";
customField.dataType = DataTypeEnum.NAMED_ID;
customField.dataTypeSpecified = true;
customField.DataValue = new DataValue();
customField.DataValue.Items = new object[1];
customField.DataValue.ItemsElementName = new ItemsChoiceType[18]; //18 is a named ID value. Inspect ItemChoiceTypes for values.
customField.DataValue.Items[0] = "Free"; //Or Paid, or Premium
customField.DataValue.ItemsElementName[0] = ItemsChoiceType.NamedIDValue;
GenericObject customFieldsc = new GenericObject();
customFieldsc.GenericFields = new GenericField[1];
customFieldsc.GenericFields[0] = customField;
customFieldsc.ObjectType = new RNObjectType();
customFieldsc.ObjectType.TypeName = "IncidentCustomFieldsc";
GenericField cField = new GenericField();
cField.name = "c";
cField.dataType = DataTypeEnum.OBJECT;
cField.dataTypeSpecified = true;
cField.DataValue = new DataValue();
cField.DataValue.Items = new object[1];
cField.DataValue.Items[0] = customFieldsc;
cField.DataValue.ItemsElementName = new ItemsChoiceType[1];
cField.DataValue.ItemsElementName[0] = ItemsChoiceType.ObjectValue;
incident.CustomFields = new GenericObject();
incident.CustomFields.GenericFields = new GenericField[1];
incident.CustomFields.GenericFields[0] = cField;
incident.CustomFields.ObjectType = new RNObjectType();
incident.CustomFields.ObjectType.TypeName = "IncidentCustomFields";
}
I have the following method which is called from Ajax:
[Authorize]
[ValidateInput(false)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public JsonNetResult CreateOrUpdateTimeRecord(TimeRecord tr)
{
TimeRecord trLocal;
if (tr.Id == -1 || tr.Id == 0)
{
trLocal = new TimeRecord
{
Description = tr.Description,
StartTime = tr.StartTime,
EndTime = tr.EndTime,
User =new myTimeMvc.Models.NHibernate.Models.User {Id = tr.User.Id},// _userRepo.Get(tr.User.Id),
Hdt = new Hdt {Id = tr.Hdt.Id}//_hdtRepo.Get(tr.Hdt.Id)
};
_timeRepo.Insert(trLocal);
}
else
{
trLocal = _timeRepo.Get(tr.Id);
trLocal.Description = tr.Description;
trLocal.StartTime = tr.StartTime;
trLocal.EndTime = tr.EndTime;
_timeRepo.Update(trLocal);
}
...
}
As you can see my TimeRecord has a reference to User and Hdt. Now I started to work with NHibernate Profiler which complains when I resolve my properties by loading them from their coresponding repositories. Which is clear to me since I actually don't need to query the database for that since I have the ID's for this objects.
User = _userRepo.Get(tr.User.Id),
Hdt = _hdtRepo.Get(tr.Hdt.Id)
But I'm not 100% sure if I can use this instead:
User =new myTimeMvc.Models.NHibernate.Models.User {Id = tr.User.Id},,
Hdt = new Hdt {Id = tr.Hdt.Id}
I guess NHibernate lazy proxies work the same way since they only contain just the ID of the related object and load the rest when it is needed. Do I have to attach this "new" oject anyway to my session?
Can someone tell me what is the correct way to do this?
Cheers,
Stefan
There are a few ways how to achieve that. One of them could be using the Load() method. Check Ayendes post: NHibernate – The difference between Get, Load and querying by id, an extract:
Load will never return null. It will always return an entity or throw an exception. Because that is the contract that we have we it, it is permissible for Load to not hit the database when you call it, it is free to return a proxy instead.
Other words, we can do something like this
User = _userRepo.Load(tr.User.Id),
Hdt = _hdtRepo.Load(tr.Hdt.Id)
Where the Load would be encapsulating the session.Load()
Im new to using WCF for silverlight, could someone help me please. This is driving me mad!!
my code in service1.cs is:
[OperationContract]
public List<PublishedSoftwareItem> GetSoftwareByArea(int ID)
{
ProductionFileManager manager = new ProductionFileManager();
using (LinqToSQLPublishedSoftwareDataContext con = new LinqToSQLPublishedSoftwareDataContext())
{
var listOfSoftware = new List<PublishedSoftwareItem>();
var getSoftware = from a in con.PublishedSoftwares
join b in con.Areas on a.AreaID equals b.AreaID
join c in con.ImageDataStores on a.ImageStoreID equals c.ID
select new PublishedSoftwareItem
{
Description = a.SoftwareDescription,
PublishLink = a.PublishLink,
Title = a.SoftwareName,
SoftwareImage = manager.GetImageFromDatabase(ID)
};
listOfSoftware = getSoftware.ToList();
return listOfSoftware;
}
}
when i update my reference.cs gets messed up and the service doesnt work correctly anymore. Ive unchecked the reuse types checkbox and that didnt help. Please someone help. Ask if you need more info
you should reface this links:
WCF Service Reference and Get Use
I am developing a wcf service for Windows 8 APP. But I'm choked up at one point.
The following method, it is coming data in the database using entity. But this the data returns back to a class type. My question , if result is null what can I sent person who will this method
public AnketorDTO AnketorBul(string tc, string pass)
{
_entity = new AnketDBEntities();
var result = (from i in _entity.Anketors
where i.TC == tc
where i.Sifre == pass
select i).ToList();
if (!result.Any())
-->>> return new AnketorDTO();
Anketor anketor = result.First();
return Converter.ConvertAnketorToAnketorDTO(anketor);
}
with this methot I SENT it by creating a new class type but part which use this methot does not work because the values become null. how can we prevent it.
Client :
AnketorDTO anketor = await client.AnketorBulAsync(txtKullanici.Text, txtSifre.Password);
**if (anketor != null)
lblError.Text = anketor.Adi;**
else
lblError.Text = "Hata";
Can you try this method to see, if it works?
_entity = new AnketDBEntities();
var result = _entity.Anketors.FirstOrDefault(yourexpressions);
Suppose I have 2 tables : tab1, tab2, with EF and Wcf Ria service, there are 2 entity Tab1, Tab2 available at client side of domaincontext.
Then I want to get the entityset dynamically in code, like
MyDomainContext.Entities("Tab1");
How can I do this?
In your client side code you will have a reference, such as:
using System.ServiceModel.DomainServices.Client;
Then you would load collections of your entities like so:
var ctx = new MyDomainContext();
ctx.Load<tab1>( _ctx.GetTab1Query(), LoadBehavior.RefreshCurrent, (op) =>
{
var data = op.Entities;
} , null );
In the above code snippet your server side domain service has provided you with the GetTab1Query.
I've seen this in Kyle McClellan's code in his ComboBoxDataSource. He takes a string parameter and calls an Operation (or Query). This is now part of the RiaServicesContrib project in the ComboBoxDataSource module.
The essentials (from ComboBoxDataSource.cs, Refresh method):
Type domainContextType = this.DomainContext.GetType();
MethodInfo operationInfo = domainContextType.GetMethods().Where(
m => (m.Name == this.OperationName) && (m.GetParameters().Count() == this.Parameters.Count)).FirstOrDefault();
this.Operation = (InvokeOperation)operationInfo.Invoke(this.DomainContext, this.Parameters.Select(p => p.Value).ToArray());
this.Operation.Completed += this.OnInvokeCompleted;