我需要访问一个安全的网络服务,
标头中的每个请求都需要携带令牌.
标头中的每个请求都需要携带令牌.
我知道Web服务的端点,
我也知道如何创建令牌.
但我无法看到Web服务的WSDL.
在C#中有没有办法创建一个没有WSDL文件的soap客户端.
解决方法
我已经验证这个使用
HttpWebRequest class的代码有效:
- // Takes an input of the SOAP service URL (url) and the XML to be sent to the
- // service (xml).
- public void PostXml(string url,string xml)
- {
- byte[] bytes = Encoding.UTF8.GetBytes(xml);
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
- request.Method = "POST";
- request.ContentLength = bytes.Length;
- request.ContentType = "text/xml";
- using (Stream requestStream = request.GetRequestStream())
- {
- requestStream.Write(bytes,bytes.Length);
- }
- using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
- {
- if (response.StatusCode != HttpStatusCode.OK)
- {
- string message = String.Format("POST Failed with HTTP {0}",response.StatusCode);
- throw new ApplicationException(message);
- }
- }
- }
您需要创建正确的SOAP信封并将其作为“xml”变量传递.这需要一些阅读.我发现这个SOAP Tutorial很有帮助.