引用或例子 - 在.NET SOAP客户端? [英] SOAP client in .NET - references or examples?

查看:159
本文介绍了引用或例子 - 在.NET SOAP客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:

我创建一个web服务的网站,将提供多种类型的通过SOAP简单的服务和其他可能的协议了。我们的目标是,以方便例如转换,RSS解析,邮件检查等多种类型的工作要做。该网站将主要在初级开发者的目标。

I am creating a webservices site which will provide many types of simple services over SOAP and possibly other protocols too. The goal is to make it easy to do for example conversions, RSS parsing, spam checks and many other types of work. The site will be targeted mostly at beginner developers.

我的问题:

我从来没有开发的任何C#或.NET为此事。我做了一些破解VB6多年前,但仅此而已。现在,我需要一些在C#中通过SOAP做RPC调用的例子。我试图在网上搜索,以及堆栈溢出,发现这一点,但并没有找到很多资源,我不知道如何排名的资源(这是老了吗?这是不正确的?等等)。

I have never developed any C#, or .NET for that matter. I did hack some VB6 many years ago but that's it. Now I need some examples of doing RPC calls over SOAP in C#. I have tried to search the web, and Stack Overflow, to find this but didn't find many resources, and I have no idea how to rank the resources (which are old? which are incorrect? etc).

我创建了一个简单的例子服务,这是在PHP这样调用:

I have created a simple example service, which is called like this in PHP:

<?php
$client = new SoapClient('http://webservi.se/year'); //URL to the WSDL
echo $client->getCurrentYear(); //This method returns an integer, called "year"
?>

我现在想在C#尽可能容易地调用此方法。所有参考文献和例子都非常欢迎。我从哪开始呢?哪个类/模块/我什么可以利用?

I now want to call this method as easily as possible in C#. All references and examples are very welcome. Where do I begin? Which classes/modules/whatever can I utilize?

解决方案不必如果有更好的通信框架(后端,就是要扩展),在所有涉及SOAP,但请注意,服务器端PHP实现在Unix微软这样的专有解决方案超出在服务器端的问题。

The solution does not have to involve SOAP at all if there are better communication frameworks (the back end is meant to be extensible), but note that the server side is implemented in PHP on Unix so proprietary solutions from Microsoft are out of the question on the server side.

请注意,我需要这个,所以我可以写文档可能J.随机Web开发遵循(即使他们是在共享虚拟主机)。因此,我认为最好的办法应该是为此在code而已,但即使其它这样的方式当然是欢迎的。

Note that I need this so I can write documentation possible for J. Random Web Developer to follow (even if they are on shared web hosting). I therefore think the best approach should be to do this in code only, but even other ways of doing this are of course welcome.

推荐答案

据我了解你想调用从C#客户端应用程序的Web服务。你已经拥有了服务,并发布的WSDL文件(纠正我,如果我错了)。现在,最简单的方法是生成C#应用程序代理类(这个过程被称为添加服务引用)。有这样做的2主要途径是,.NET提供ASP.NET服务,这是在做SOA的老样子,和WCF约翰建议,这是从微软最新的框架,并提供了许多协议,包括开放式和MS proprietery的。

As I understand you want to call your web service from C# client application. You already have the service and published WSDL file (correct me if I'm wrong). Now, the simplest way is to generate proxy classes in C# application (this process is called adding service reference). There are 2 main way of doing this, .NET provides ASP.NET services, which is old way of doing SOA, and WCF as John suggested, which is the latest framework from MS and provides many protocols, including open and MS proprietery ones.

现在,理论已经足够,让做一步一步

Now, enough theory and lets do it step by step


  1. 在Visual Studio中打开项目(或创建一个新的)

  2. 右键单击该项目(该项目,而不是解决方案)在解决方案资源管理器,然后单击添加服务引用

  3. 一个对话框应显示在下面的截图显示。输入您的WSDL文件的URL,然后点击OK。请注意,如果你击中​​确定后收到错误信息,请尝试删除?WSDL部分来自URL。

  1. Open your project (or create a new one) in visual studio
  2. Right click on the project (on the project and not the solution) in Solution Explorer and click Add Service Reference
  3. A dialog should appear shown in screenshot below. Enter the url of your wsdl file and hit Ok. Note that if you'll receive error message after hitting ok, try removing ?wsdl part from url.

展开解决方案资源管理服务引用并双击ServiceReference1(名称可能有所不同)。你应该看到生成的代理类名称和命名空间。在我的例子中,命名空间是WindowsFormsApplication1.ServiceReference1,代理类的名称是Service1Client。正如我前面所说,类名称可能你的情况有所不同。

Expand Service References in Solution Explorer and double click ServiceReference1 (name may vary). You should see generated proxy class name and namespace. In my case, the namespace is WindowsFormsApplication1.ServiceReference1, the name of proxy class is Service1Client. As I said above, class names may vary in your case.

转到您的C#源$ C ​​$ C。添加使用WindowsFormsApplication1.ServiceReference1

Go to your C# source code. Add using WindowsFormsApplication1.ServiceReference1.

Service1Client服务=新Service1Client();

年整型= service.getCurrentYear();

希望这会有所帮助,如果你遇到任何问题,请告诉我们。

Hope this helps, if you'll encounter any problem, let us know.

这篇关于引用或例子 - 在.NET SOAP客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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