C#客户端如何调用wsdl文件 [英] C# client how to invoke wsdl file

查看:987
本文介绍了C#客户端如何调用wsdl文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My customer gave me a .wsdl file to access their webservices. Using VS2008 I can create a project, but I don't know how to use the .wsdl file in it.

推荐答案

您不要调用WSDL文件,您可以从文件中添加服务引用。

You don't invoke WSDL file, you add service reference from the file.

要添加引用,请在项目上单击鼠标右键,选择添加服务引用。将路径粘贴到wsdl文件,然后按 Go

To add reference, right click on the project, select Add Service Reference. Paste path to your wsdl file and hit Go.

如果要使用旧版Web Service客户端,请选择添加Web参考并从那里粘贴到wsdl文件的路径。

If you want to use legacy Web Service client, select Add Web Reference and paste path to the wsdl file from there.

我建议使用WCF(添加服务参考选项)。

I recommend to use WCF (Add Service Reference option).

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

To use the service reference add code like this:

var serviceClient = new ServiceReferenceName.MyClassClient();
serviceClient.DoSomething();

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

You also need to update config file with the server URL that you customer should provide you with:

<client>
  <endpoint address="http://UrlFromYourCustomerHere"
            binding="basicHttpBinding"
            bindingConfiguration="xxx"
            contract="MyServiceReference.xxx"
            name="xxx/>
</client>

这篇关于C#客户端如何调用wsdl文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆