大家好 如何在本地系统中使用wsdl文件来使用webservice,我试过在添加Web引用中指定文件路径,但得到的错误是在文档的顶层无效。 谢谢
Hi all How can i use a wsdl file in my local system to consume webservice, i have tried by specifying file path in 'Add Web Reference' , but getting the error 'Invalid at the top level of the document.' Thanks
推荐答案打开Visual Studio,创建一个Web项目或控制台应用程序,然后右键单击该项目并从上下文菜单中选择添加服务引用。 输入文件将路径和名称放入框中并导入WSDL - 这将生成一个简单,非常基本的WCF客户端供您使用。您应该在生成的代码中找到YourservicenameClient类,该类应该具有WSDL合同中每个已定义方法的方法。 实例化客户端并调用方法你想打电话 - 这就是全部! open Visual Studio, create a web project or console app, and then right-click on the project and pick "Add Service Reference" from the context menu. 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(不使用默认创建的远程URL),您可以在代理客户端的构造函数中轻松完成此操作:
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是表示要连接的URL的字符串(而不是配置中包含的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文件
发布评论