Web Analytics Made Easy -
StatCounter sending and receiving soap requests - CodingForum

Announcement

Collapse
No announcement yet.

sending and receiving soap requests

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • sending and receiving soap requests

    hi guys,
    I have been given an assignment to send an sms using a sms server. This SMS server receives soap requests and send soap requests. I had tried a lotta code to send sms but was unsucessfull. Finally I did manage to send the sms to the server but was unable to receive an acknowledgement from them.
    this was the soap request the sms server requested
    <?xml version='1.0' encoding='UTF-8'?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <SOAP-ENV:Body>
    <ns1:method-name xmlns:ns1="urn:SOAPSend"
    SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <user xsi:type="xsd:string">test</user>
    <pass xsi:type="xsd:string">test</pass>
    <to xsi:type="xsd:string">447968123456</to>
    <from xsi:type="xsd:string">SOAPSend</from>
    <note xsi:type="xsd:string">note</note>
    <subaccount xsi:type="xsd:string">subaccount</subaccount>
    <report xsi:type="xsd:int">0</report>
    ... other parameters ...
    </ns1:method-name>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>


    And this was the acknowledgement they would send
    <?xml version='1.0' encoding='UTF-8'?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <SOAP-ENV:Body>


    <ns1:method-nameResponse xmlns:ns1="urn:SOAPSend"
    SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <return xmlns:ns2="http://schemas.xmlsoap.org/soap/encoding/"
    xsi:type="ns2:Array" ns2:arrayType="xsd:int[1]">
    <item xsi:type="xsd:int">577925</item>
    </return>
    </ns1:method-nameResponse>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>


    This is the code that I have written

    Dim messageBytes As Byte()
    Dim webRequest As HttpWebRequest = CType(webRequest.Create("http://sms.mxtelecom.com/soap/servlet/rpcrouter"), HttpWebRequest)
    webRequest.ContentType = "text/xml;charset=utf-8"

    webRequest.Headers.Add("SOAPMethodName", "sendSMSMessage")
    webRequest.Method = "POST"
    strEnvelope = "<?xml version='1.0' encoding='UTF-8'?>"
    strEnvelope = strEnvelope + "<SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>"
    strEnvelope = strEnvelope + "<SOAP-ENV:Body>"
    strEnvelope = strEnvelope + "<ns1:sendSMSMessage xmlns:ns1='urn:SOAPSend' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>"
    strEnvelope = strEnvelope + "<user xsi:type='xsd:string'>jhgjhg</user>"
    strEnvelope = strEnvelope + "<pass xsi:type='xsd:string'>jgugu</pass>"
    strEnvelope = strEnvelope + "<to xsi:type='xsd:string'>" & number & "</to>"
    strEnvelope = strEnvelope + "<from xsi:type='xsd:string'>Inpora</from>"
    strEnvelope = strEnvelope + "<note xsi:type='xsd:string'>testing</note>"
    strEnvelope = strEnvelope + "<subaccount xsi:type='xsd:string'></subaccount>"
    strEnvelope = strEnvelope + "<report xsi:type='xsd:int'>1</report>"
    strEnvelope = strEnvelope + "<text xsi:type='xsd:string'>" & txtMessage.Text & "</text>"
    strEnvelope = strEnvelope + "<flash xsi:type='xsd:boolean'>false</flash>"
    strEnvelope = strEnvelope + "<split xsi:type='xsd:int'>0</split>"
    strEnvelope = strEnvelope + "</ns1:sendSMSMessage>"
    strEnvelope = strEnvelope + "</SOAP-ENV:Body>"
    strEnvelope = strEnvelope + "</SOAP-ENV:Envelope>"


    webRequest.ContentLength = strEnvelope.Length
    messageBytes = Encoding.ASCII.GetBytes(strEnvelope)
    Dim requestStream As Stream = webRequest.GetRequestStream
    requestStream.Write(messageBytes, 0, messageBytes.Length)
    Dim webResponse As HttpWebResponse
    Dim responseStream As Stream

    Try
    webResponse = CType(webRequest.GetResponse, HttpWebResponse)
    responseStream = webResponse.GetResponseStream
    Dim response As Byte()
    -> responseStream.Read(response, 0, Integer.MaxValue)
    Dim clientData As String
    clientData = System.Text.Encoding.Default.GetString(response)
    Dim sr As New StreamReader(responseStream)


    Now it gives me an error at the point -> responseStream.Read(response, 0, Integer.MaxValue)
    Message "Value cannot be null.
    Parameter name: buffer" String
    I tried figuring out what the problem is. I guess maybe I am not receiving the acknowledgement from the server. I have no idea actually. But i do receive the sms . So the sms is being sent through but i do need to process the acknowledgement.
    I would be thanful if you guys can help me in this regard.


Working...
X