WCFサービスを初めて使用しています。 Dynamics CRMからレコードを取得するWCFサービスを作成しています。 IISにデプロイした後、私はそのサービスをテストしました。そして、xml形式のデータを返すときと戻すときは、サービスはうまく動作します。WCFシリアル化と逆シリアル化
namespace WCF_CRM_Multipolar
{
[Serializable]
[DataContract(Namespace = "http://mlpt-web.com/CRM/services")]
public class Presid
{
[DataMember]
public string PresalesID
{
get;
set;
}
[DataMember]
public string OptiName
{
get;
set;
}
[DataMember]
public string CustomerName
{
get;
set;
}
[DataMember]
public string Status
{
get;
set;
}
[DataMember]
public Nullable<DateTime> ClosedDate
{
get;
set;
}
[DataMember]
public DateTime CreateOn
{
get;
set;
}
}
}
IService
:ここにいます私のコードはService.svc
public List<Presid> GetPresalesIdList(string userlogin)
{
List<Presid> idsales = new List<Presid>();
Presid presales = new Presid();
string cmb = userdomain + userlogin;
InitializeCRMService(userName, passWord, domain);
try
{
if (!string.IsNullOrEmpty(userlogin))
{
QueryExpression qe = new QueryExpression("systemuser");
string[] cols = { "businessunitid", "domainname", "systemuserid" };
qe.Criteria = new FilterExpression();
qe.Criteria.AddCondition("domainname", ConditionOperator.Equal, cmb);
qe.ColumnSet = new ColumnSet(cols);
var guid = _service.RetrieveMultiple(qe);
userid = ((EntityReference)guid[0].Attributes["businessunitid"]).Id;
systemid = (Guid)guid[0].Attributes["systemuserid"];
QueryExpression query = new QueryExpression("opportunity");
string[] cols2 = { "new_presalesid","createdon", "ownerid", "name", "parentaccountid", "statecode", "estimatedclosedate" };
query.Criteria = new FilterExpression();
query.Criteria.AddCondition("ownerid", ConditionOperator.Equal, systemid);
query.ColumnSet = new ColumnSet(cols2);
EntityCollection preid = _service.RetrieveMultiple(query);
string prsId = string.Empty;
string optNm = string.Empty;
string cusNm = string.Empty;
string stscde = string.Empty;
DateTime closedate;
DateTime open;
foreach (Entity enty in preid.Entities)
{
presales = new Presid();
if (enty.Attributes.Contains("new_presalesid"))
{
prsId = enty.GetAttributeValue<string>("new_presalesid");
if (!string.IsNullOrEmpty(prsId))
{
presales.PresalesID = prsId;
}
else
{
presales.PresalesID = null;
}
}
if (enty.Attributes.Contains("name"))
{
optNm = enty.GetAttributeValue<string>("name");
if (!string.IsNullOrEmpty(optNm))
{
presales.OptiName = optNm;
}
else
{
presales.OptiName = null;
}
}
//cusNm = enty.GetAttributeValue<EntityReference>("parentaccountid").Name;
if (enty.Attributes.Contains("parentaccountid"))
{
cusNm = ((EntityReference)enty["parentaccountid"]).Name;
if (!string.IsNullOrEmpty(cusNm))
{
presales.CustomerName = cusNm;
}
else
{
presales.CustomerName = null;
}
}
if (enty.Attributes.Contains("statecode"))
{
stscde = enty.FormattedValues["statecode"];
if (!string.IsNullOrEmpty(stscde))
{
presales.Status = stscde;
}
else
{
presales.Status = null;
}
}
if (enty.Attributes.Contains("estimatedclosedate"))
{
closedate = enty.GetAttributeValue<DateTime>("estimatedclosedate");
if (closedate != null)
{
presales.ClosedDate = closedate;
}
}
if (enty.Attributes.Contains("createdon"))
{
open = enty.GetAttributeValue<DateTime>("createdon");
if (open != null)
{
presales.CreateOn = open;
}
}
idsales.Add(presales);
}
return idsales;
}
}
catch (Exception ex)
{
}
return idsales;
}
Presidクラスです
[OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "/GetPresalesIdList/{userlogin}")] List<Presid> GetPresalesIdList(string userlogin);
私はこのURLから呼び出すことによって、自分のPCから試験した場合、これらのコードがうまく実行します。他の部門がデシリアライズそれによって、このサービスを呼び出したい
http://localhost:8076/Service1.svc/Getpresalesidlist/user
しかし、彼らは彼らが行うことができないことを言いますそれ。だから彼らは私に問題の原因を探すように頼んでいます。私のコードはまだシリアル化されていると思うので、デシリアライズできません。その話に基づいて、質問があります:
- 私のコードはまだシリアル化されていますか?それが真実なら、それをシリアル化可能にする方法は? 私はインターネット上でシリアライズ可能な例を探しています。
MemoryStream
と呼ばれるものを使用します。しかし、私は自分のコード内でそれを実装することができません。だから私のコードをシリアライズ可能にする方法を教えてください。
こんにちは@Ross Bush、私はサービスを実行すると、そのデータをxml形式で返します。私のコードはdeserializeableですか?はいの場合は、メソッドの問題をデシリアライズします。 –
回答を更新します。上記の[Serializable]属性を使用する必要はありません。 –
だから '[Serializable]'を削除するだけでいいですか?私は試してみるよ。私はそれを試した後に私はあなたに知らせます。別の質問は、WCF内の各クラスについて、私はすべてのクラスに対して同じ名前空間を使用するか、各クラスに対して異なる名前空間を使用する必要がありますか? –