我一起工作Model.dll使用在Windows應用程序和Web服務的同一類庫
using System;
using System.Collections.Generic;
using System.Text;
namespace root
{
public class Customer
{
private int _Id;
public int Id
{
get { return _Id; }
set { _Id = value; }
}
private string _Name;
public string Name
{
get { return _Name; }
set { _Name = value; }
}
}
}
ASP.NET Web服務參考Model.dll如此我可以在web方法使用:
[WebMethod]
public string HelloWorld(root.Customer customer) {
return "Hello World";
}
參考Model.dll和Web Service的Windows應用程序(1)。
root.Customer newCustomer = new Customer();
newCustomer.Id = 1;
newCustomer.Name = "Name";
ws.Service ws = new root.ws.Service();
ws.HelloWorld(newCustomer);
^problem here
錯誤:參數 '1':無法從 'root.Customer' 轉換爲 'root.ws.Customer'
(1)右鍵 - >和Web參考 - >在此解決方案的Web服務 - >點擊Service.asmx - > 輸入Web引用名稱:WS - >單擊添加引用
更新:我可以從
public string HelloWorld(Customer customer)
更改生成Reference.cs文件行
public string HelloWorld(root.Customer customer)
所以功能會尋找真正的模型,而不是代理對象,但不是真正的答案。
我不想在每次Web參考更新後編輯此文件。
如何強制使用真實模型?
+1。另請參閱[WCF手動方式...正確的方式](http://www.code-magazine.com/Article.aspx?QuickID=0809101)。 – TrueWill