简体   繁体   English

使用带有XML数据的C Sharp Soap 1.1调用远程Web服务? 如何

[英]call remote webservice using c sharp soap 1.1 with xml data? how to

here I am calling a webservice using ajax jquery now I want to do the same job with soap 1.1 xml data 在这里,我正在使用ajax jQuery调用Web服务,现在我想对soap 1.1 xml数据执行相同的工作

w3school method link w3school方法链接

I am using the same method above now I want to do with soap 1.1 asp.net using xml c sharp 我现在使用与上面相同的方法,现在我想使用xml C Sharp处理soap 1.1 asp.net

I tried to give web link as web refrence in advance option also but it says 我也尝试提供网络链接作为预先的网络参考选项,但是它说

schema not match 模式不匹配

can you give me a link to code project aso.net soap 1.1 with xml link or any step by step method what to do with that data 您能给我一个带有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>

You wont be able to read the xml file using Soap 1.1. 您将无法使用Soap 1.1读取xml文件。

Soap is a protocol (Simple Object Access Protocol), not a file type. 肥皂是一种协议(简单对象访问协议),而不是文件类型。 It happens to use xml as a way to map the hierarchical structure of the objects, but it is not going to be able to pick up an xml file and just use it. 碰巧使用xml作为映射对象的层次结构的一种方式,但是它无法选择一个xml文件并仅使用它。

Soap web services like you tried to add use xsd to define a schema and that is represented by the WSDL file (Web Service Definition Language). 像您尝试添加的Soap Web服务一样,使用xsd定义一个模式,该模式由WSDL文件(Web服务定义语言)表示。

Your best bet for this is to make a web request to the url of the xml file and then handle the file in code. 最好的选择是向xml文件的URL发出Web请求,然后用代码处理该文件。

Something like: 就像是:

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();
            }
        }

EDIT: To do a POST request: 编辑:要执行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 });
    }

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

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