简体   繁体   English

创建C#客户端无需使用内置的“添加服务参考...”即可使用SOAP服务。

[英]Create C# client consumes SOAP service without using built-in 'Add Service Reference…'

My company provides SOAP service over Https. 我公司通过Https提供SOAP服务。 I need to write a library that consumes that SOAP service using C#. 我需要编写一个使用C#使用该SOAP服务的库。 I am using code generated by "Add Service Reference..." feature of Visual Studio 2008, but it creates a class for each function (there are many of them) exposed by service that i think overkill. 我正在使用由Visual Studio 2008的“添加服务引用...”功能生成的代码,但是它为我认为过大的服务所暴露的每个函数(其中有很多)创建了一个类。 My question is there another way to write a consumer without using "Add Service Reference..." ? 我的问题是没有使用“添加服务参考...”来编写使用者的另一种方法吗?

您可以通过创建SOAP消息并发送Web请求来实现,就像在此SOAP客户端Web请求中一样

You can use svcutil.exe command line utility to create the proxy class for your service.Add that proxy class with generated config file in your project.All the service methods will be available through that class. 您可以使用svcutil.exe命令行实用工具为您的服务创建代理类,然后在项目中添加带有生成的配置文件的代理类,所有服务方法都可以通过该类使用。 Here are the steps for Generating proxy clas. 这是生成代理分类的步骤。

  1. Open Visual Studio Command prompt. 打开Visual Studio命令提示符。

  2. Go to the specific Folder where you want to place you generated class.eg type "cd D:\\\\Services 转到要放置生成类的特定文件夹。例如,键入“ cd D:\\\\ Services

  3. run the command "svcutil.exe YourSerivceURL" 运行命令“ svcutil.exe YourSerivceURL”

This command will generate the class for your service in "D:\\\\Services" folder with output.config file. 此命令将使用output.config文件在“ D:\\\\ Services”文件夹中为您的服务生成类。 you have to copy the client configration section from the output.config file and add in you web.config file where you want to refer the service. 您必须从output.config文件复制“客户端配置”部分,并在要引用服务的web.config文件中添加。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM