简体   繁体   English

连接到未知的SOAP Web服务

[英]Connect to Unknown SOAP Web Service

I would like to build an app in C# that connects to an Apache AXIS web service and performs the following operations via SOAP. 我想用C#构建一个应用程序,该应用程序连接到Apache AXIS Web服务并通过SOAP执行以下操作。

  1. Login in to the server. 登录到服务器。
  2. POST string data to server 将字符串数据发布到服务器
  3. Receive and display server response 接收并显示服务器响应

Here's the tough part. 这是困难的部分。 I do not have access to the server, nor do I know where the .JWS file is located on the server. 我无权访问服务器,也不知道.JWS文件在服务器上的位置。 I was able to get to the WSDL file in my web browser, so I know a "Login" operation exists as well as an operation to take in data. 我能够在Web浏览器中访问WSDL文件,因此我知道存在“登录”操作以及获取数据的操作。

I have tried accessing the web service via URL, but I keep getting this message: 我尝试通过URL访问Web服务,但始终收到以下消息:

Hi there, this is an AXIS service! 您好,这是一个AXIS服务!

Perhaps there will be a form for invoking the service here... 也许这里会有一种调用服务的表格...

In summary, is there anyway I can connect to this web service when all I have is the URL of the WSDL file? 总而言之,当我只有WSDL文件的URL时,是否可以连接到该Web服务? Are web services accessible via URL? 是否可以通过URL访问Web服务?

Thank you 谢谢

Use WCF , and generate client proxies to the web service using the svcutil.exe tool. 使用WCF ,并使用svcutil.exe工具生成Web服务的客户端代理。

running svcutil.exe http://url.to/webservice?WSDL the_wsdl.wsdl /language:C# should generate proxy classes you can use in your C# project, and you'd call the service eg like 运行svcutil.exe http://url.to/webservice?WSDL the_wsdl.wsdl /language:C#应该生成可以在C#项目中使用的代理类,因此您可以调用该服务,例如

  BasicHttpBinding myBinding = new BasicHttpBinding(); //might not even need these
                    // 2 lines if you ran svcutil.exe directly on the web service URL
  EndpointAddress myEndpoint = new EndpointAddress("http://url.to/webservice");
  TestClient client = new TestClient(myBinding,myEndpoint); //the generated classes
                                                            // svcutil.exe created
  client.SomeOperation(42); // call an SomeOperation of the web service 

Thanks for everyone's help. 谢谢大家的帮助。 Looking back on this question, I can see how severely confused I was. 回顾这个问题,我可以看到自己有多困惑。 Here is the solution I followed. 这是我遵循的解决方案。

Assuming you know the URL of the WSDL file of the service you wish to connect to then just do the following. 假设您知道要连接的服务的WSDL文件的URL,则只需执行以下操作。

  1. Boot up Visual Studio 启动Visual Studio
  2. On the top toolbar navigate to Data -> Add New Data Source then choose Service in the new dialog 在顶部工具栏上,导航到“数据”->“添加新数据源”,然后在新对话框中选择“服务”
  3. In the address bar, enter the URL of the wsdl file (EXAMPLE: http://server.com/services/displayName?wsdl ) 在地址栏中,输入wsdl文件的URL(例如: http ://server.com/services/displayName?wsdl)
  4. Near the bottom of the dialog, change the namespace to something relevant to the project (EXAMPLE: sampleService) 在对话框底部附近,将名称空间更改为与项目相关的名称(例如:sampleService)
  5. Now Visual Studio should compile the client proxies for you that you can use to access the web services on your server. 现在,Visual Studio应该为您编译客户端代理,您可以使用它们来访问服务器上的Web服务。 To access one of the services, all you need to do is create a new object from the class. 要访问其中一项服务,您需要做的就是从该类中创建一个新对象。

      //Example sampleService.ClassName test = new sampleService.ClassName(); test.displayName("Jack"); 

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

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