Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 如何将SOAP信封传递给需要对象的web服务方法_Xml_Web Services_Soap - Fatal编程技术网

Xml 如何将SOAP信封传递给需要对象的web服务方法

Xml 如何将SOAP信封传递给需要对象的web服务方法,xml,web-services,soap,Xml,Web Services,Soap,我在soap信封中传递一个XML字符串,web服务方法希望将一个对象作为参数传递给它的某个内部类,该类与XML具有相同的结构,而客户机对此类一无所知。我需要从XML字符串中填充对象。我正在使用HttpWebRequest来实现这一点,但到目前为止运气不佳 客户端代码: HttpWebRequest request = CreateWebRequest(url); XmlDocument soapEnvelopeXml = new XmlDocument(); soapEnvelopeXml.Lo

我在soap信封中传递一个XML字符串,web服务方法希望将一个对象作为参数传递给它的某个内部类,该类与XML具有相同的结构,而客户机对此类一无所知。我需要从XML字符串中填充对象。我正在使用
HttpWebRequest
来实现这一点,但到目前为止运气不佳

客户端代码:

HttpWebRequest request = CreateWebRequest(url);
XmlDocument soapEnvelopeXml = new XmlDocument();
soapEnvelopeXml.LoadXml(@"<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><" + methodName + " xmlns='http://xsp.com/module'><MyClass><strXML xsi:type='xsd:string'>" + xml + "</strXML></MyClass></" + methodName + "></soap:Body></soap:Envelope>");
using (Stream stream = request.GetRequestStream())
{
    soapEnvelopeXml.Save(stream);
}
using (WebResponse response = request.GetResponse())
{
    using (StreamReader rd = new StreamReader(response.GetResponseStream()))
    {
        string soapResult = rd.ReadToEnd();                    
    }
}

任何帮助都将不胜感激。

没有运气意味着什么?它以一个错误结束,或者结果是错误的?我的意思是如何从客户端soap信封中传递的XML字符串填充TestMethod MyClass参数。现在TestMethod中的MyClass参数为null。那么,如何将XML反序列化为MyClass参数,以便正确填充它呢?
[WebMethod]
public string TestMethod(MyClass myClass)
{
    if (myClass == null)
        return "myClass is null";
    if (myClass.strXML == null)
    {               
        return "myclass.strXML is null";                
    }            
    return myClass.strXML.toString();
}

public class MyClass
{
    private object sXML;        
    public object strXML
    {
        get
        {
            return this.sXML;
        }
        set
        {
            this.sXML = value;
        }
    }        
}