在 C# 中连接到 Web 服务

Connecting to a web service in C#

我是服务的新手,所以我可能明显遗漏了一些东西。我得到了一个示例字符串来提取一些数据,它工作正常,就像下面的工作查询字符串一样,它将 return 我想要的 JSON 。当我尝试在 visual studio 的 'Add Service Reference' 表单中输入没有查询的相同字符串时,我得到以下信息:

There was an error downloading 'https://test.acme.com/PathA/1.0/PathB/Endpoint/_vti_bin/ListData.svc/$metadata'. The request failed with HTTP status 404: Not Found. Metadata contains a reference that cannot be resolved: 'https://test.acme.com/PathA/1.0/PathB/Endpoint'. There was no endpoint listening at a that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. The remote server returned an error: (404) Not Found. If the service is defined in the current solution, try building the solution and adding the service reference again.

工作查询字符串

https://test.acme.com/PathA/1.0/PathB/Endpoint?foo=VALUE&date=2013-01-01

基本字符串

https://test.acme.com/PathA/1.0/PathB/Endpoint

我的问题是访问网络服务的最佳方式是什么。我的同事提到他们查询 wsdl 文件以访问这些方法。但是查询以下 return 什么都没有。我的猜测是没有公开任何内容来列出 Web 服务方法,但我不确定为什么这允许我使用特定的 URL.

提取数据

https://test.acme.com/PathA/1.0/PathB/Endpoint?WSDL

这是 VS 添加服务引用中的旧错误 JSON 服务

Servie with JSON 在添加服务引用

中无法正常工作

你可以看看这个问题听到

can-i-generate-a-service-reference-automatically-for-a-rest-wcf-service mixing-add-service-reference-and-wcf-web-http-a-k-a-rest-endpoint-does-not-work

我找到了解决此问题的方法,尝试这些链接:

consume-odata-service-and-get-result-in-json

Consuming-a-Json-WebService-from-a-Csharp-or-VB-Ap