×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Aug 2013
    Posts
    4

    Exclamation Post Xml data to .asmx (SOAP) service Windows Phone 8

    I am trying to post Xml data to .asmx service.

    I can't add the service as a service reference to my project. So I have to post data as a Xml format.

    I try with this code.

    Please tell me what is wrong with my code...


    Code:
    private void TextBlock_Tap(object sender, System.Windows.Input.GestureEventArgs e)
            {
                StringBuilder soapRequest = new StringBuilder("<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/\">");
                soapRequest.Append("<soap:Body>");
                soapRequest.Append("blamethod");
                soapRequest.Append("<VersionInfo>");
                soapRequest.Append("<Major>1</Major>");
                soapRequest.Append("<Minor>0</Minor>");
                soapRequest.Append("</VersionInfo>");
                soapRequest.Append("<UserInfo>");
                soapRequest.Append("<req1>1</req1>");
                soapRequest.Append("<req2>1</req2>");
                soapRequest.Append("<req3>1</req3>");
                soapRequest.Append("<req4>1</req4>");
                soapRequest.Append("</UserInfo>");
                soapRequest.Append("<Request>");
                soapRequest.Append("<user>bla1</user>");
                soapRequest.Append("<pword>bla2</pword>");
                soapRequest.Append("</Request>");
                soapRequest.Append("</blamethod>");
                soapRequest.Append("</soap:Body>");
                soapRequest.Append("</soap:Envelope>");
                
                soapString = soapRequest.ToString();
                HttpWebRequest request = HttpWebRequest.Create("https://blabla.com.tr/bla1.asmx?op=blamethod") as HttpWebRequest;
                request.Credentials = new NetworkCredential("username", "password");
                request.BeginGetResponse(new AsyncCallback(GetRequestStreamCallback), request);
            }
            private void GetRequestStreamCallback(IAsyncResult asynchronousResult)
            {
                MessageBox.Show(asynchronousResult.ToString());
    
                char[] soapCharArr = soapString.ToCharArray();
                HttpWebRequest req = (HttpWebRequest)asynchronousResult.AsyncState;
                byte[] buffer = Encoding.UTF8.GetBytes(soapString.ToCharArray(), 0, soapCharArr.Length);
                Stream postStream = req.EndGetRequestStream(asynchronousResult);
                postStream.Write(buffer, 0, buffer.Length);
                postStream.Close();
                req.BeginGetResponse(new AsyncCallback(GetResponseCallBack), req);
    
            }
            private void GetResponseCallBack(IAsyncResult asynchronousResult)
            {
                HttpWebRequest req = (HttpWebRequest)asynchronousResult.AsyncState;
                HttpWebResponse response = (HttpWebResponse)req.EndGetResponse(asynchronousResult);
                System.IO.Stream responseStream = response.GetResponseStream();
                System.IO.StreamReader reader = new System.IO.StreamReader(responseStream);
                string data = reader.ReadToEnd();
                responseStream.Close();
                this.Dispatcher.BeginInvoke(() => { MessageBox.Show(data.ToString()); });
                reader.Close();
                responseStream.Close();
            }
    My SOAP Web Service is;

    Code:
    POST /bla1.asmx HTTP/1.1
        Host: blabla.com
        Content-Type: text/xml; charset=utf-8
        Content-Length: length
        SOAPAction: "http://blabla.com/blamethod"
        
    
        <?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>
            <blamethod xmlns="http://blabla.com/">
              <VersionInfo>
                <Major>int</Major>
                <Minor>int</Minor>
              </VersionInfo>
              <UserInfo>
                <req1>decimal</req1>
                <req2>string</req2>
                <req3>string</req3>
                <req4>string</req4>
              </UserInfo>
              <Request>
                <user>decimal</user>
                <pword>string</pword>
              </Request>
            </blamethod>
          </soap:Body>
        </soap:Envelope>
    Response;

    Code:
     HTTP/1.1 200 OK
        Content-Type: text/xml; charset=utf-8
        Content-Length: length
    
        <?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>
            <blamethodResponse xmlns="blabla.com/">
              <Response>
                <Information>
                  <name>string</name>
                  <surname>string</surname>
                </Information>
                <Contract_x0020_List>
                  <Contract>
                    <accountno>decimal</accountno>
                    <Plan>string</Plan>
                  </Contract>
                  <Contract>
                    <accountno>decimal</accountno>
                    <Plan>string</Plan>
                  </Contract>
                </Contract_x0020_List>
              </Response>
            <blamethodResponse>
          </soap:Body>
        </soap:Envelope>

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,750

    Re: Post Xml data to .asmx (SOAP) service Windows Phone 8

    That BeginGetResponse (in TextBlock_Tap) looks strange, is not it supposed to be something GetRequestStream? (BeginGetRequestStream, GetRequestStreamAsync)

  3. #3
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    686

    Re: Post Xml data to .asmx (SOAP) service Windows Phone 8

    Hmmm why cant you add the web service as a service reference to your project?
    Have you tried to enable HTTP GET & POST to the service and call it using simple http post with the proper parameters (and not xml) ?

Similar Threads

  1. SOAP Parsing in windows phone
    By mandardac in forum Windows Phone General
    Replies: 2
    Last Post: 2012-11-01, 17:37
  2. SOAP web service request with credentials for Windows Phone 7
    By sreerajvr in forum Windows Phone General
    Replies: 16
    Last Post: 2012-04-03, 10:17
  3. Java2Me client working with dot net asmx service
    By kioskpay in forum Mobile Java Networking & Messaging & Security
    Replies: 6
    Last Post: 2010-04-23, 10:37
  4. Connect to phone from windows service
    By stealth117 in forum PC Suite API and PC Connectivity SDK
    Replies: 4
    Last Post: 2008-09-27, 19:32
  5. No Phone Connected in Windows Service
    By windsocks in forum PC Suite API and PC Connectivity SDK
    Replies: 0
    Last Post: 2006-01-03, 10:02

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×