简体   繁体   English

使用C#连接到Web服务

[英]Connecting to a web service in C#

I'm new to services so it might be something obvious I'm missing. 我是服务的新手,所以我可能很想念它。 I was given an example string to pull in some data and it works fine given something like the working query string bellow it will return the JSON I want. 给了我一个示例字符串以提取一些数据,并且给定类似工作查询字符串的东西,它可以很好地工作,它将返回我想要的JSON。 When I try to input the same string without the query into the 'Add Service Reference' form in visual studio however I get the following: 当我尝试在Visual Studio的“添加服务引用”表单中输入不带查询的相同字符串时,得到以下信息:

There was an error downloading ' https://test.acme.com/PathA/1.0/PathB/Endpoint/_vti_bin/ListData.svc/ $metadata'. 下载' https://test.acme.com/PathA/1.0/PathB/Endpoint/_vti_bin/ListData.svc/ $ metadata'时出错。 The request failed with HTTP status 404: Not Found. 请求失败,HTTP状态为404:找不到。 Metadata contains a reference that cannot be resolved: ' https://test.acme.com/PathA/1.0/PathB/Endpoint '. 元数据包含无法解析的引用:“ 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. 这通常是由不正确的地址或SOAP操作引起的。 See InnerException, if present, for more details. 有关更多详细信息,请参见InnerException(如果存在)。 The remote server returned an error: (404) Not Found. 远程服务器返回错误:(404)找不到。 If the service is defined in the current solution, try building the solution and adding the service reference again. 如果服务是在当前解决方案中定义的,请尝试构建解决方案并再次添加服务引用。

Working Query String 工作查询字符串

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

Base String 基本字串

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

My question is what is the best way to access the web service. 我的问题是访问Web服务的最佳方法是什么。 My coworkers mentioned they query the wsdl file to get access to the methods. 我的同事提到他们查询wsdl文件以获得对方法的访问。 However querying the following returns nothing. 但是,查询以下内容不会返回任何内容。 My guess is that there's nothing exposed to list the web service methods, but I wasn't sure why that's allow me to pull in data using the specific URL. 我的猜测是没有列出Web服务方法的信息,但是我不确定为什么这允许我使用特定的URL提取数据。

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

This is old error in VS Add service reference with JSON service 这是VS使用JSON服务添加服务参考中的旧错误

Servie with JSON not work properly in Add service reference 带有JSON的Servie在添加服务参考中无法正常工作

you can checkout this issues hear 您可以签出此问题,听听

can-i-generate-a-service-reference-automatically-for-a-rest-wcf-service mixing-add-service-reference-and-wcf-web-http-aka-rest-endpoint-does-not-work 我可以自动为休息的WCF服务生成服务参考吗? 混合添加服务参考和WCF网站http aka休息端点无法正常工作

And i got some workaround for this try thses links : 我对此尝试链接有一些解决方法:

consume-odata-service-and-get-result-in-json 消耗数据服务并获取json结果

Consuming-a-Json-WebService-from-a-Csharp-or-VB-Ap 从Csharp或VB-Ap消费Json WebService

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

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