【发布时间】:2014-05-03 04:22:39
【问题描述】:
我需要测试第三方开发的网络服务。第三方既没有提供 WSDL 也没有提供 ASMX。他们只提供了 Web 服务的名称、url 和原始 XML 请求的示例。我现在正试图拨打电话,但 我不知道该怎么做!
我尝试obtain an wsdl by executing visual studio's wsdl.exe,但我收到了一个错误,比如"The HTML document does not contain identifying information about the Web service."
在 Visual Studio 上,我尝试添加一个服务引用,提供 Web 服务的 url。我得到了an error downloading '<url>/_vti_bin/ListData.svc/$metadata'. Metadata contains a reference that cannot be resolved. 可能是因为 Web 服务是 ASMX 而不是 WCF?
我认为接下来会尝试use SOAP,但我使用code from here 创建了一个类,该类创建soap 信封、Web 请求、将soap 信封插入到Web 请求中,然后是一个进行适当调用的main。但是,当 Visual Studio 在 IE11 上执行该类时,我得到一个相当随机的 HTTP Error 403.14 - Forbidden, the Web server is configured to not list the contents of this directory。
除了所有这些尝试之外...在 Visual Studio 2012 上调用外部 Web 服务的正确方法是什么,无需 WSDL、ASMX 或添加 Web 引用?
更新:
我使用@Ian 提供的代码创建了一个类。我执行了代码(F5),得到了HTTP error 403.14 Forbidden,如下所示。
public class TestingClassHttp
{
/// <summary>
/// An HTTP based Client for sending request
/// </summary>
public class HTTPClient : WebClient
{
/// <inheritdoc/>
/// <remarks>Modify the timeout of the web request</remarks>
protected override WebRequest GetWebRequest(Uri address)
{
WebRequest request = base.GetWebRequest(address);
request.Timeout = (int)new TimeSpan(0, 30, 0).TotalMilliseconds;
return request;
}
/// <inheritdoc/>
public string Request(string endPoint, string content)
{
using (WebClient client = new WebClient())
{
client.Headers[HttpRequestHeader.Accept] = "text/html,application/xhtml+xml,application/xml";
client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
String response = client.UploadString(endPoint, "POST", content);
return response;
}
}
}
static void Main(string[] args)
{
HTTPClient client = new HTTPClient();
Console.WriteLine(client.Request("http://.../_ws/products?o=get", ""));
}
}
【问题讨论】:
标签: c# web-services visual-studio wsdl asmx