如何在Web解决方案中引用项目之间的类

时间:2015-06-04 18:19:35

标签: c# asp.net

我有一个项目存储一个Address类,我想要使用Web Service项目和Web项目。

项目1 :(持有地址类)

namespace GeoClass
{
    public partial class Address 
    {        
        private string city { get; set; };        
        private string street { get; set; };       
        private string zip { get; set; };
    }
}
  • Web服务项目:我添加了GeoClass作为参考

    using GeoClass;
    
    namespace WSGeo
    {
         public class jsonGeo : System.Web.Services.WebService
         {
             [WebMethod}
             public jsonOut  GetAddress(Address inputAddr)
             {
                //do something
             }
         }
    }
    
  • 在Web应用程序中,将WebService项目添加为Web服务,并添加Project 1作为参考。我把Webservice中的方法称为:

    using GeoClass;
    
    Address inputAddress = GetInputAddress();  //This function pull the data from                  the text boxes 
    
    string WSResult;
    WSGeo jsonGeo = new WSGeo;
    
    WsResult = WS.jsonGeo.GetAddress(inputAddress); // I have in invalid argument error right here
    

我在这里错过了什么吗?感谢

1 个答案:

答案 0 :(得分:0)

我在这里找到答案:C# Web Service and Web Site sharing library, service returns different "type" of library object

我只有这个问题与Web应用程序框架3.5(库和Web服务项目是框架4.5),当我用框架4.5(所有Web应用程序,Web服务和库)构建另一个我没有经历过这个问题。