我希望序列化一个实体框架对象(用户),并使用典型的webClient.OpenWrite方法将其发送到php脚本。我不知道这是否是一种好方法,但我在SOAP对象序列化方面遇到了很多问题。
我最初的“用户”实体如下所示:
[Table("TableUsers")]
public class User
{
public User()
{
Products = new HashSet<Product>();
}
public int Id { get; set; }
[Required]
[StringLength(4000)]
[Index(IsUnique = true)]
public string UserName { get; set; }
[StringLength(4000)]
public string UserCookie { get; set; }
[StringLength(4000)]
public string CompanyName { get; set; }
...
public virtual ICollection<Product> Products { get; set; }
}当我试图序列化所有这些东西并使用下一段代码将其发送到服务器时:
using (Stream postStream = Client.OpenWrite("http://test.com/analytics.php"))
{
SoapFormatter formatter = new SoapFormatter();
formatter.Serialize(postStream, user);
}好吧,好吧。我用SoapIgnore属性标记了产品集合。而且似乎这个属性不起作用,因为我得到了同样的错误。然后,我决定从用户类中删除用户构造函数,并选择了宾果!已执行序列化!(好吧,我可以在没有接口初始化的情况下生活)
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:clr="http://schemas.microsoft.com/soap/encoding/clr/1.0" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<i2:User_782DCAD431DFFDCAE6D6A91B7338AB23B0463133F84A5181874089B6BAEBDBC5 id="ref-1" xmlns:i2="http://test.com">
<User_x002B__x003C_Id_x003E_k__BackingField>6</User_x002B__x003C_Id_x003E_k__BackingField>
<User_x002B__x003C_UserName_x003E_k__BackingField id="ref-3">user@test.com</User_x002B__x003C_UserName_x003E_k__BackingField>...这个soapFormatter有什么问题?为什么没有外泄?我应该如何标记所有这些类和属性,以生成一个打印得很好的soap查询?
发布于 2016-03-08 18:53:42
尝试将其放在上下文类中:
public class MyContext : DbContext
{
public MyContext()
{
this.Configuration.ProxyCreationEnabled = false;
}
....
}下面是包含更多详细信息的链接:https://msdn.microsoft.com/en-us/data/jj592886.aspx
https://stackoverflow.com/questions/35875327
复制相似问题