【发布时间】:2017-09-06 00:19:18
【问题描述】:
1.类库项目 C#,我创建了客户类库项目,它只有一个名为“Customer.cs”的类文件
namespace CustomerClassLibrary
{
public class Customer
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
}
2。网络服务项目
我在参考文件夹下添加了 CustomerClassLibrary dll
创建了两个方法
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public string GetAllTickets(CustomerClassLibrary.Customer C )
{
string statuscode;
if (C.FirstName=="JOHN")
{
statuscode = "success";
}
else{
statuscode = "failure";
}
return statuscode;
}
3.客户端应用程序(C# Windows 应用程序)
在引用下添加了CustomerClassLibrary dll
在Service Reference文件夹下添加WebService引用(创建代理类)
var ss = new SRMUserRegServiceReference.SRMUserRegistrationSoapClient();
按钮 1 点击:
string status = ss.HelloWorld();
Console.WriteLine(status);
当我执行此操作时,我可以成功检索“Hello World 状态。一切看起来都很好。
按钮2点击:
CustomerClassLibrary.Customer C;
C.FirstName = "John";
C.LastName = "TEST";
string returnString =ss.GetAllTickets(C);
Console.WriteLine(returnString);
在这里,当我尝试在 GetAllTickets(C) 方法中传递“客户 C 对象时,我收到错误。
你能指导我如何通过网络服务传递“单一对象”吗?
两个错误,我得到了:
错误 1
“ClientApplicationCallWebService.SRMUserRegServiceReference.SRMUserRegistrationSoapClient.GetAllTickets(ClientApplicationCallWebService.SRMUserRegServiceReference.Customer)”的最佳重载方法匹配有一些无效参数 Testing\ClientApplicationCallWebService\ClientApplicationCallWebService\Form1.cs 50 34 ClientApplicationCallWebService
错误 2
参数 1:无法从 'CustomerClassLibrary.Customer' 转换为 'ClientApplicationCallWebService.SRMUserRegServiceReference.Customer' Testing\ClientApplicationCallWebService\ClientApplicationCallWebService\Form1.cs 50 51 ClientApplicationCallWebService
【问题讨论】:
-
您遇到什么错误?还尝试将您的类 Customer 标记为 [Serializable]
-
您的代码甚至无法编译 - GetAllTickets() 不返回任何内容。
-
在方法结束时返回 statusCode。在方法中设置断点会发生什么?
-
当我尝试执行客户端应用程序时,出现两个错误。
-
嘿 Isma,请指导我如何将 Customer 类标记为 [Serializable]
标签: c# asp.net web-services object