如何使用一个WSDL [英] How to use a WSDL
问题描述
我需要消耗一个Web服务。他们给我的WSDL文件。
我应该怎么做将其添加到我的网站,并开始使用它作为代理。
(如果我把它放在一个虚拟目录可以发现,但它给予我真正的Web服务的连接?)
I need to consume a Web Service. They sent me the WSDL file. What should I do to add it to my website and start using it as the proxy. ( If I put it on a Virtual Directory it can be discovered, but does it grant me the connection with the real web service?)
推荐答案
我就火了Visual Studio 2008中,创建一个Web项目(或控制台应用程序 - 无所谓),并在项目然后右击并选择从上下文菜单中选择添加服务引用。
I would fire up Visual Studio 2008, create a web project (or console app - doesn't matter), and then right-click on the project and pick "Add Service Reference" from the context menu.
输入文件路径和名称入禁区,并导入WSDL - 这将生成一个简单,很基本的WCF客户端供您使用。你应该找到在生成的code应该具备哪些方法为每个WSDL合同的定义方法YourservicenameClient级。
Enter the file path and name into the box and import the WSDL - this will generate a simple, very basic WCF client for you to use. You should find a "YourservicenameClient" class in the generated code which should have methods for each of the defined methods on the WSDL contract.
实例化客户端,并呼吁要调用的方法 - 这是所有有
Instantiate the client and call the methods you want to call - that's all there is!
YourServiceClient client = new YourServiceClient();
client.SayHello("World!");
更新:
如果你需要指定远程URL(不使用默认创建的),你可以很容易地做到这一点在代理客户的构造:
UPDATE:
if you need to specify the remote URL (not using the one created by default), you can easily do this in the constructor of the proxy client:
YourServiceClient client = new YourServiceClient("configName", "remoteURL");
,其中CONFIGNAME是端点使用(你会使用除URL的所有设置),以及remoteURL的名字重新$ P $字符串psenting的URL连接到(而不是一个包含在配置)。
where "configName" is the name of the endpoint to use (you will use all the settings except the URL), and the "remoteURL" is a string representing the URL to connect to (instead of the one contained in the config).
马克
这篇关于如何使用一个WSDL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!