简体   繁体   English

在ASP.NET Web服务上传递实体

[英]Passing Entity on ASP.NET Web Service

This might be very easy, but What I am trying to do here is, I am trying to pass a Customer Object to a Web Service Method. 这可能很容易,但是我在这里要做的是,我正在尝试将客户对象传递给Web服务方法。 Customer class is on Entity namespace and it is serializable, and I am adding reference to both of my ASP.NET application which calls web service and pass Entity.Customer Object and also in WebService which accepts Enity.Customer Object. Customer类位于Entity名称空间上,并且可以序列化,并且我要添加对我的ASP.NET应用程序的引用,该应用程序调用Web服务并传递Entity.Customer对象,还添加了对接受Enity.Customer Object的WebService的引用。

Web Service Method Web服务方式

[WebMethod]
public void AddCustomer(Entity.Customer c)
{}

ASP.NET Applcation ASP.NET应用

Entity.Customer c = new Entity.Customer;
webservice.AddCustomer(c);

Error 错误

The best overloaded method match for 'TestApplication.localhost.Service1.AddCustomer(TestApplication.localhost.Customer)' has some invalid arguments 'TestApplication.localhost.Service1.AddCustomer(TestApplication.localhost.Customer)'的最佳重载方法匹配具有一些无效的参数

I tried changing the web service to accept Object and later cast that object to Customer.Entity, the Application compiles but I was getting XML generation errors. 我尝试将Web服务更改为接受Object,然后将该对象转换为Customer.Entity,应用程序进行了编译,但出现XML生成错误。

Are you generating the web service method using the 'Add Web Reference' method from within Visual Studio? 您是否正在Visual Studio中使用“添加Web引用”方法生成Web服务方法?

This is a compile-issue right? 这是编译问题吧? You application doesn't want to compile? 您的应用程序不想编译吗? Just go to the definition of the method and make sure you are passing the same customer object as specified in the method definition - usually the generated web service method generates a proxy version of the object and you need to pass that exact same class. 只需转到方法的定义,并确保您传递的对象与方法定义中指定的对象相同-通常,生成的Web服务方法会生成该对象的代理版本,并且您需要传递该完全相同的类。

Often the helper methods generated through a service method expect the local generated objects - this is because some elements of the server-side objects aren't serialized, or are handled slightly differently because of the serialization. 通过服务方法生成的帮助程序方法通常期望本地生成的对象-这是因为服务器端对象的某些元素未序列化,或者由于序列化而处理的方式略有不同。

Try: 尝试:

TestApplication.localhost.Customer c = new TestApplication.localhost.Customer();
webservice.AddCustomer(c);

This way you're using the generated objects, with the correctly serialized properties, rather than the original object. 这样,您将使用具有正确序列化属性的生成对象,而不是原始对象。

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

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