2

私はクラスを持っています:

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="MyClass", Namespace="http://model.common.party.ent.gfdi.be")]
[System.SerializableAttribute()]
public class MyClass : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged 
{

    [System.Runtime.Serialization.OptionalFieldAttribute()]
    private string firstname;

    [System.Runtime.Serialization.OptionalFieldAttribute()]
    private string lastname;
}

インスタンスを作成します:

   var myClass = new MyClass() { lastname = "AAA", firstname = "BBB" };

このインスタンスを Web サービスに送信したいと思います。

このオブジェクトを Web サービスに送信したいと思います。Web サービスが受け取るメッセージは次のようになります。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:membership="http://service.common.party.ent.gfdi.be 
http://service.common.party.ent.gfdi.be">
   <soapenv:Header/>
   <soapenv:Body>
      <membership:find>
         <membership:in0>
           <membership:lastname>AAA</membership:lastname>
           <membership:firstname>BBB</membership:firstname>
         </membership:in0>
      </membership:find>
   </soapenv:Body>
</soapenv:Envelope>

私はこれを試しました:

HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(myurl);
webRequest.Headers["Authorization"] = "Basic " + "XXXXXXXXXXXXXX=";
webRequest.ContentType = "text/xml; charset=UTF-8";
webRequest.Method = "POST";

XmlDocument soapEnvelopeXml = CreateSoapEnvelope();
InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);

IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);

asyncResult.AsyncWaitHandle.WaitOne();

string soapResult;
using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
{
    using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
    {
        soapResult = rd.ReadToEnd();
    }
    Console.Write(soapResult);
}

private static void InsertSoapEnvelopeIntoWebRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest)
{
    using (Stream stream = webRequest.GetRequestStream())
    {
        soapEnvelopeXml.Save(stream);
    }
}

private static XmlDocument CreateSoapEnvelope()
{
    XmlDocument soapEnvelop = new XmlDocument();
    soapEnvelop.LoadXml(@"<SOAP-ENV:Envelope xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/1999/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/1999/XMLSchema""><SOAP-ENV:Body><HelloWorld xmlns=""http://tempuri.org/"" SOAP-ENV:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/""><int1 xsi:type=""xsd:integer"">12</int1><int2 xsi:type=""xsd:integer"">32</int2></HelloWorld></SOAP-ENV:Body></SOAP-ENV:Envelope>");
    return soapEnvelop;
}

何か案が ?

ありがとう、

4

1 に答える 1