C#客户端如何调用wsdl文件

Gat*_*spy 14 .net c# wsdl visual-studio-2008

我的客户给了我一个.wsdl文件来访问他们的web服务.使用VS2008我可以创建一个项目,但我不知道如何在其中使用.wsdl文件.

Ale*_*Aza 50

您不调用WSDL文件,而是从文件中添加服务引用.

要添加引用,请右键单击项目,然后选择Add Service Reference.粘贴wsdl文件的路径并点击Go.

在此输入图像描述

如果要使用旧版Web服务客户端,请Add Web Reference从那里选择并粘贴到wsdl文件的路径.

我建议使用WCF(添加服务引用选项).

要使用服务引用,请添加如下代码:

var serviceClient = new ServiceReferenceName.MyClassClient();
serviceClient.DoSomething();
Run Code Online (Sandbox Code Playgroud)

您还需要使用客户应为您提供的服务器URL更新配置文件:

<client>
  <endpoint address="http://UrlFromYourCustomerHere"
            binding="basicHttpBinding"
            bindingConfiguration="xxx"
            contract="MyServiceReference.xxx"
            name="xxx/>
</client>
Run Code Online (Sandbox Code Playgroud)