开发者

Webservice remove the NameSpace from the webMethod Parameter Problem

I Have Create the webMethod

Service:

[WebMethod]    
  public void GetCommission(List <BOLibrary.Flight.DTContract>Loc)
 {
 }

At the client side i am Passing the parameter Client

List<BOLibrary.Flight.DTContract> BoList = new List<BOLibrary.Flight.DTContract>();
        BOLibrary.Flight.DTContract dtConboj = new BOLibrary.Flight.DTContract();
        d开发者_开发问答tConboj.ValidatingCarrier = "AA";
        BoList.Add(dtConboj);
        BOLibrary.Flight.DTContract[] pass = BoList.ToArray();
        service.GetCommission(pass);

But the Problem is that the service.GetCommission(pass) accpect the argument of servicenameSpace.DTContract but in client in client i have BOLibrary.Flight.DTContract

so how can i pass the parameter to the to the Service. Pleae see the snapshot of the error message

Webservice remove the NameSpace from the webMethod Parameter Problem


This is the expected behavior. There is no way to change it.

If you want to be able to use the exact same type on the client and the service, then you need to move to WCF.


I believe this is the expected behaviour when using ASMX/WebMethod's and Web References. That is, the client and server are expected to be mutually exclusive codebase.

If you want to use common entities/library code between both sides of the services you could use SvcUtil with the /reference parameter to generate a proxy that will work with WCF and use class definitions from a shared library. It's fairly easy to move your client code from Web References (generated with wsdl.exe - I think?) to WCF Service References (generated with svcutil.exe).


The client code generated by the webservice is creating it's own version of the server side object.

By definition, a webservice lives outside the scope of your application and defines an interface object, as such - no object in the client domain can possibly be the same as the one defined by the service.

Put a different way - the webservice defines the whole transport layer, including any transport objects involved. you can't use your own objects (Regardless of namespace) in this transport layer because they are not known to the server - the server only knows the objects it defines.

So in this case you'd have to create a list of objects from the server's type if you want to communicate with it.

As mentioned by others, there are other communication methods that would allow you to share libraries between the client and the server (i.e. WCF) if this is what you want to do.


I'm not sure why your web page class is being modified with the XmlInclude, SoapInclude & XmlRoot attributes because I think they only apply if you intend to XML/soap serialize the web page itself.

What the compile error is saying is the BOLibrary.Flight.DTContract class does not come from the FPCommission.CommissionService namespace in the generated WebReference code. All your client-side objects used for calling the service should be from FPCommission namespace. If you are sharing an assembly between the client and the service then your code won't work. Just use the FPCommission.DTContract class instead of the BOLibrary.Flight.DTContract class and your code should work.


one way to get this to work is to implement an EntityTranslator which is a pattern that takes the data contract entity and 'translates' it to the business entity.

it's rather simple, really. All you do is create two methods: one that takes the data contract entity and creates a business entity from it, and another that takes the business entity and creates a data contract entity.

an example with additional links can be found here


I think AutoMapper should be able to do what you want.

e.g.

using AutoMapper;

// ...

Mapper.CreateMap<BOLibrary.Flight.DTContract, FPCommission.DTContract>();
Mapper.Map<List<BOLibrary.Flight.DTContract>, FPCommission.DTContract[]>(BoList);

Notice that you only need to set up the mapping between the basic class types -- AutoMapper will take care of the mapping between collections.

You should try to put the call to Mapper.CreateMap() somewhere central where it will only be called once, as it will be expensive if it is called frequently.


In your code the GetCommission method is expecting a List. Your function call is sending an Array – Not a list?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜