[英]how to pass object through asp.net web service
1. Class Library Project C# , I have created Customer Class Library Project which has only one class file called "Customer.cs" 1.类库项目 C#,我创建了“客户类库项目”,该项目只有一个名为“ Customer.cs”的类文件。
namespace CustomerClassLibrary
{
public class Customer
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
}
2. Web Service Project 2. Web服务项目
I have added CustomerClassLibrary dll under the reference folder 我在参考文件夹下添加了CustomerClassLibrary dll
Created two methods 创建了两种方法
[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. Client Application (C# Windows application) 3.客户端应用程序(C#Windows应用程序)
Added CustomerClassLibrary dll under the reference 在参考下添加了CustomerClassLibrary dll
Added WebService reference under the Service Reference folder (Created Proxy class) 在“服务引用”文件夹下添加了WebService引用(创建的代理类)
var ss = new SRMUserRegServiceReference.SRMUserRegistrationSoapClient();
Button 1 Click: 按钮1单击:
string status = ss.HelloWorld();
Console.WriteLine(status);
When I execute this , I can able retrieve "Hello World status Successfully. Everything looks good. 执行此操作后,我可以成功检索“ Hello World状态。一切看起来不错。
Button 2 click : 按钮2单击:
CustomerClassLibrary.Customer C;
C.FirstName = "John";
C.LastName = "TEST";
string returnString =ss.GetAllTickets(C);
Console.WriteLine(returnString);
Here, When I tried to pass "Customer C object in GetAllTickets(C) methods, I am getting error. 在这里,当我尝试在GetAllTickets(C)方法中传递“客户C对象”时,出现错误。
Can you please guide me how do I pass "Single Object" through the web service? 您能否指导我如何通过Web服务传递“单个对象”?
Two Errors, I am getting : 两个错误,我得到:
Error 1 错误1
The best overloaded method match for 'ClientApplicationCallWebService.SRMUserRegServiceReference.SRMUserRegistrationSoapClient.GetAllTickets(ClientApplicationCallWebService.SRMUserRegServiceReference.Customer)' has some invalid arguments Testing\\ClientApplicationCallWebService\\ClientApplicationCallWebService\\Form1.cs 50 34 ClientApplicationCallWebService
“ ClientApplicationCallWebService.SRMUserRegServiceReference.SRMUserRegistrationSoapClient.GetAllTickets(ClientApplicationCallWebService.SRMUserRegServiceReference.Customer)”的最佳重载方法匹配具有一些无效的参数Testing \\ ClientApplicationCallWebService \\ ClientApplicationCallWebService \\ Form1.cs 50 34 ClientApplicationCallWebService
Error 2 错误2
Argument 1: cannot convert from 'CustomerClassLibrary.Customer' to 'ClientApplicationCallWebService.SRMUserRegServiceReference.Customer' Testing\\ClientApplicationCallWebService\\ClientApplicationCallWebService\\Form1.cs 50 51 ClientApplicationCallWebService
参数1:无法从“ CustomerClassLibrary.Customer”转换为“ ClientApplicationCallWebService.SRMUserRegServiceReference.Customer” Testing \\ ClientApplicationCallWebService \\ ClientApplicationCallWebService \\ Form1.cs 50 51 ClientApplicationCallWebService
Try : 尝试:
CustomerClassLibrary.Customer C = new CustomerClassLibrary.Customer();
C.FirstName = "John";
C.LastName = "TEST";
string returnString =ss.GetAllTickets(C);
Console.WriteLine(returnString);
ClientApplicationCallWebService.SRMUserRegServiceReference.Customer C = new ClientApplicationCallWebService.SRMUserRegServiceReference.Customer();
C.FirstName = "JOHN";
C.LastName = "TEST";
string returnString =ss.GetAllTickets(C);
Console.WriteLine(returnString);
Finally, I found the answer, I created instance for Customer Class the below, now I can able to pass the object. 最后,我找到了答案,下面我为Customer Class创建了实例,现在我可以传递对象了。 Thanks all
谢谢大家
ClientApplicationCallWebService.SRMUserRegServiceReference.Customer C = new ClientApplicationCallWebService.SRMUserRegServiceReference.Customer();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.