Relatively new to wcf and Silverlight. I had been banging my head against the wall trying to digest WCF and the contract concept. I found a web post that showed a way to make WCF work. As you'll see it doesn't follow the classical WCF form (no datacontracts).
Here is an example of the code. Note that the ImageData object is not part of a data contract but simply declared as a normal object in a class cs file with get and set properties.
Despite the fact that this isn't "regulation" it does work. The service reference to the service automatically moves over the ImageData class and a number of other pieces of information to make this work.
This worked fine. However I hit an error I've hit twice before where I'm told that some obscure assembly is not present to allow the service to be accessed. This has happened twice before. In all three cases I was able recreate the service and the service reference (but I had to change the names of both because it seemed they already existed in the project). The first two times this fixed my problem.
This time I used the same fix but now the code, instead of returning a list of Image开发者_JS百科Data as is indicated in the signature of the function is now returning a type called "GetImageDataReponse" and I no longer can iterate through the list of ImageData Objects that it used to return. In looking at the definition of "GetImageDataReponse" I find that it looks like another VS2010 generated function that has the list of ImageData embedded in it. It seems to have added another layer of abstraction over the return type (List).
I'm not sure what is causing the odd "missing assembly" errors which seem to occur randomly and cause me to rebuild the service. Now I'm not sure why I am getting these new return types from functions that have a clear return type specified and worked before.
Any help would be appreciated. I hope to be able to prevent having to rebuild the service and the service reference in the first place.
Below is the code that used to work and then the defination of "GetImageDataReponse" in the reference.cs file.
Thanks, Fig000
[OperationContract]
public List<ImageData> GetImageData(int imageID)
{
List<ImageData> ImageDataList = new List<ImageData>();
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["CN_eLogWeb"].ConnectionString.ToString());
SqlDataReader dr = null;
string sql = @"SELECT isnull(i.ANI,'') as ANI, isnull(i.DonorCorpID,0) as DonorCorpID,isnull(i.DonorUnitID,0) as DonorUnitID,isnull(i.AgencyID,0) as AgencyID,
isnull(i.PickupDT,'1/1/1900') as PickupDT, isnull(u.InBoundSortedStatusID,1) as InboundSortedStatusID, isnull(u.FollowupRequired,0) as FollowupRequired
from InboundSorted i
left join UserSortSessionInfo u on i.IncomingID=u.IncomingID
left join Image img on i.ImageID=img.ImageID where img.ImageID=" + imageID;
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
ImageData oImageData = new ImageData
{
ANI = Convert.ToString(dr["ANI"]),
DonorCorpID = Convert.ToInt32(dr["DonorCorpID"]),
DonorUnitID = Convert.ToInt32(dr["DonorUnitID"]),
AgencyID = Convert.ToInt32(dr["AgencyID"]),
PickupDT = Convert.ToDateTime(dr["PickupDT"]),
Status = GetInboundSortedStatus(Convert.ToInt32(dr["InboundSortedStatusID"])),
FollowupRequired = Convert.ToBoolean(dr["FollowupRequired"])
};
ImageDataList.Add(oImageData);
}
}
con.Close();
return ImageDataList;
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.MessageContractAttribute(WrapperName="GetImageDataResponse", WrapperNamespace="", IsWrapped=true)]
public partial class GetImageDataResponse {
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="", Order=0)]
public System.Collections.Generic.List<acSilverlightLib.ImgServiceRef2.ImageData> GetImageDataResult;
public GetImageDataResponse() {
}
public GetImageDataResponse(System.Collections.Generic.List<acSilverlightLib.ImgServiceRef2.ImageData> GetImageDataResult) {
this.GetImageDataResult = GetImageDataResult;
}
}
if (dr.HasRows)
{
while (dr.Read())
{
ImageData oImageData = new ImageData
{
ANI = Convert.ToString(dr["ANI"]),
DonorCorpID = Convert.ToInt32(dr["DonorCorpID"]),
DonorUnitID = Convert.ToInt32(dr["DonorUnitID"]),
AgencyID = Convert.ToInt32(dr["AgencyID"]),
PickupDT = Convert.ToDateTime(dr["PickupDT"]),
Status = GetInboundSortedStatus(Convert.ToInt32(dr["InboundSortedStatusID"])),
FollowupRequired = Convert.ToBoolean(dr["FollowupRequired"])
};
ImageDataList.Add(oImageData);
}
}
con.Close();
return ImageDataList;
}
Did you make any changes to ImageData between versions?
An issue that can cause this is missing a Default (parameter-less) constructor on ImageData, or one of its properties.
精彩评论