2016-02-16 49 views
0

这里我使用AJAX的jQuery调用web服务,现在我想和SOAP 1.1 XML数据使用c sharp soap 1.1调用远程webservice xml数据?如何

w3school method link

我使用上述相同的方法,现在我想用肥皂1.1做的做同样的工作asp.net使用XML升C

我试着给网站链接的网页refrence提前选项还,但它说

架构不匹配

你能给我用XML链接或一步方法的任何步骤的链接代码项目aso.net SOAP 1.1做什么用的数据

<data> 
    <row> 
     <code>AAA</code> 
     <description>PIA </description> 
    </row> 
    <row> 
     <code>AAB</code> 
     <description>UK AIRline</description> 
    </row> 
...........so on 
    </data> 

回答

0

您将无法使用读取XML文件肥皂1.1。

肥皂是一种协议(简单对象访问协议),而不是文件类型。它恰好使用xml作为映射对象层次结构的方式,但是它不能获取xml文件并使用它。

像您这样的SOAP web服务试图添加使用xsd来定义一个模式,并由WSDL文件(Web服务定义语言)表示。

最好的办法是对xml文件的url进行网络请求,然后在代码中处理该文件。

喜欢的东西:

var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://www.w3schools.com/ajax/cd_catalog.xml"); 
     httpWebRequest.ContentType = "application/json; charset=utf-8"; 
     httpWebRequest.Method = "GET"; 

     using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) 
     { 
      var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); 
      using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) 
      { 
       return streamReader.ReadToEnd(); 
      } 
     } 

编辑: 做一个POST请求:

public static string RunHttpRequest(string url, object obj) 
    { 
     ServicePointManager.Expect100Continue = false; 
     var httpWebRequest = (HttpWebRequest)WebRequest.Create(url); 
     httpWebRequest.ContentType = "application/json; charset=utf-8"; 
     httpWebRequest.Method = "POST"; 

     using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) 
     { 
      var json = JsoNify(obj); 

      streamWriter.Write(json); 
      streamWriter.Flush(); 
      streamWriter.Close(); 

      var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); 
      using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) 
      { 
       return streamReader.ReadToEnd(); 
      } 
     } 
    } 
    private static string JsoNify(object obj) 
    { 
     return JsonConvert.SerializeObject(obj, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); 
    } 
+0

哎天才要比你今天有空保持在太平洋标准时间晚上7点的Skype nouman.arshad7触摸我想学习一些事情更多 –

+0

像POST请求 –

+0

我编辑我的答案,包括POST请求。 – Vaelen

相关问题