简体   繁体   English

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

[英]How to reference a class between projects in a Web solution

I have a project store a Address class which I want both Web Service project and Web project to use. 我有一个项目存储一个Address类,我想同时使用Web Service项目和Web项目。

Project 1: (holding Address class) 项目1 :(持有地址类别)

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

     using GeoClass; namespace WSGeo { public class jsonGeo : System.Web.Services.WebService { [WebMethod} public jsonOut GetAddress(Address inputAddr) { //do something } } } 
  • In Web application which is add the WebService project as web service andd add the Project 1 as reference. 在Web应用程序中,将WebService项目添加为Web服务,然后添加Project 1作为引用。 I call the method in Webservice likes this: 我这样调用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 

Did I miss something here? 我在这里想念什么吗? Thanks 谢谢

I found the answer here: C# Web Service and Web Site sharing library, service returns different "type" of library object 我在这里找到了答案: C#Web服务和网站共享库,服务返回库对象的不同“类型”

I only have this issue with the Web application framework 3.5 (library and web service projects are framework 4.5), when I built another one with framework 4.5 (all web app, web service, and library) I haven't experienced this problem yet. 我只有Web应用程序框架3.5(库和Web服务项目是框架4.5)才有这个问题,当我用框架4.5(另一个Web应用程序,Web服务和库)构建另一个项目时,我还没有遇到过这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM