【问题标题】:How to send a class variable in byte[] type to web service如何将 byte[] 类型的类变量发送到 Web 服务
【发布时间】:2019-09-01 16:05:33
【问题描述】:

我想将我的类实例变量转换为 byte[] ,然后将其传递给 Web 服务。
在我的网络服务中,我尝试将其转换回类 - 服务器收到此错误:

System.Runtime.Serialization.SerializationException: '无法找到程序集 'App_Web_xrrt4fej, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'。'

// client code:        
[Serializable]        
public class result        
{
          public string message { get; set; }
}    

protected void Page_Load(object sender, EventArgs e)    
{                   
      byte[] b = ObjectToByteArray(new result() {  message = "ok" });            
      string ss = serv.HelloWorld34(b);    
}

// server code:    
[Serializable]    
public class result    
{            
     public string message { get; set; }    
}

[WebMethod]    
public string HelloWorld34(byte[] arrBytes)    
{    
        MemoryStream memStream = new MemoryStream();    
        BinaryFormatter binForm = new BinaryFormatter();    
        memStream.Write(arrBytes, 0, arrBytes.Length);    
        memStream.Seek(0, SeekOrigin.Begin);


        // the line that has error    
        result obj = (result)binForm.Deserialize(memStream);    
        return "1";    
}

【问题讨论】:

    标签: c# asp.net web-services


    【解决方案1】:

    不要在服务器和客户端项目中声明结果类,而是创建一个单独的类库项目并在其中声明结果类。然后在您的客户端和服务器代码中引用类库项目。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-07
      • 2013-07-27
      • 2014-11-30
      • 1970-01-01
      • 1970-01-01
      • 2021-11-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多