开发者

Creating web service and client with shared types

开发者 https://www.devze.com 2023-01-05 12:40 出处:网络
I have created two wsdl files with shared types imported from xsd schema file. After that I have created web services using开发者_StackOverflow中文版 interface generated by wsdl.exe tool with paramet

I have created two wsdl files with shared types imported from xsd schema file.

After that I have created web services using开发者_StackOverflow中文版 interface generated by wsdl.exe tool with parameter /serverInterface.

Frist web service, have web method “RegisterData” with put into queue some complex object to be processed, by system “A”. As result of this method is returned Boolean (with tell us that object was registered successful).

Second web service, have web method “UpdateData” to update some data in system “B” based on this same object , with was changed in process on system “A”.

So in system “A” I have to create client for second web service, where I will call method “UpdateData” with this modified complex object us argument.

But when I’m creating this client in Visual Studio (by add web reference or add service reference) I have to create some namespace for client. And then when I’m trying to call “UpdateData” agument have different namespace for this same object received from first web service “RegisterData” method.

I would like to create first web service and second web service client , where I can use this same type object between them.

Thank you very much for help.


I don't believe this is possible with ASMX web services.

WCF does support this, however.


WCF Links:

  • WCF Developer Center
  • Beginner's Guide to Windows Communication Foundation
  • How to: Configure a Service to Reuse Existing Types

Actually, I think I may have misread your question. I though you were trying to share the same types between the client and the server. ASMX cannot do that. However, it appears you are trying to share the same types between two client proxies. You can do that easily using the WSDL.EXE tool.

Consider a schema, DataTypes.xsd, and two WSDL files that import it, ServiceA.wsdl and ServiceB.wsdl. To create the server interfaces, use:

wsdl /serverInterface /n:SharedTypes.Servers /out:Services.cs ServiceA.wsdl ServiceB.wsdl DataTypes.xsd

This will create interfaces which you can implement in order to create your services. These interfaces will both use one set of classes created from DataTypes.xsd. To create the proxy classes, simply use:

wsdl /n:SharedTypes.Proxies /out:Proxies.cs ServiceA.wsdl ServiceB.wsdl DataTypes.xsd

Notice that you do not need the /sharedTypes switch. That has a different purpose. It is for combining types of external services when you need to download the WSDL and any XSD from the service.

I have tried this using an example like yours, ServiceA posting a message into a queue, and a client picking up that message and sending it to ServiceB. It works quite well.


I agree that it is not possible to do this via the VS Web Reference functionality. To meet your requirements you can use the wsdl.exe utility with the /sharetypes switch.

For more information see Web Services Description Language Tool (Wsdl.exe)

0

精彩评论

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

关注公众号