irldev
irldev

Reputation: 409

Sending a SOAP request with Windows Phone 8

I have a SOAP 1.1 or 1.2 service that I want to use in order to query some data from a Windows Phone 8 app. The problem is, I haven't got the slightest notion about how to do this.

The SOAP request is already provided, I simply do not know how to use it. I've tried adding a WebService but I'm sort of fumbling in the dark as the SOAP request is provided from a 3rd party with little or no documentation and little or no possibility of getting any either.

I've pasted in the SOAP request below. I'd need basic step by step instructions about how to use this and get some sort of a response from it.

POST /RTPIService.asmx HTTP/1.1
Host: rtpi.sample.servers.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://testsite.com/GetRealTimeStopData"

<?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>
    <GetRealTimeStopData xmlns="http://testsite.com/">
      <stopId>int</stopId>
      <forceRefresh>boolean</forceRefresh>
    </GetRealTimeStopData>
  </soap:Body>
</soap:Envelope>

Upvotes: 3

Views: 2330

Answers (2)

Mansinh
Mansinh

Reputation: 1435

Just follow bellow step

Step1: Add Service References by right click on add References.

Step2: Now put your web service link on Service References and press go button, And also add Namespace of service Reference enter image description here

Step3: Press go buton it will take autometically all method of web service

Now add bellow code in your cs file its for example

 WhatsupServices.WhatsUpServiceSoapClient ws = new WhatsupServices.WhatsUpServiceSoapClient();
ws.ContactUsJSONCompleted += ws_ContactUsJSONCompleted;
ws.ContactUsJSONAsync(txtContactUsName.Text, txtContactUsPhone.Text, txtContactUsEmail.Text, txtContactUsComment.Text);

step6: now genrate your resopnce method

 void ws_ContactUsJSONCompleted(object sender, dynamic e)
        {
            if (e.Error != null)
            {
                MessageBox.Show(LogIn.NetworkBusyMsg, LogIn.MsgHdr, MessageBoxButton.OK);
                busyIndicator.IsRunning = false;
            }
            else
            {
                busyIndicator.IsRunning = false;
                string Result = e.Result;
                JObject obj = JObject.Parse(Result);
                string ResultCode = (string)obj["ResultCode"];
                string ResponceMessage = (string)obj["ResponseMessage"];

                if (ResultCode == "1")
                {
                    MessageBox.Show("Thank you for your message. We'll get back to you soon.", LogIn.MsgHdr, MessageBoxButton.OK);
                    NavigationService.GoBack();
                }
                else
                {
    
                }
            }
        }

Hope it will help you.

If any query than comment here.I wll help you

Upvotes: 1

nkchandra
nkchandra

Reputation: 5557

Follow these steps to use a SOAP service

-- Create a new project or Open Your Project.
-- Right-click on the Project name and click on "Add Service Reference"...
   Then provide address as "http://testsite.com/RTPIService.asmx" and click Go.
-- Once service information is downloaded, provide Namespace something like
   "MyRTPIService" at the bottom and click Ok.

Now that your proxy classes should be ready.
Go to your Mainpage.xaml.cs and type 'MyRTPIService.' there..you should probably get a list of classes of all the services provided by the SOAP service.

If you get that, then try to call the suitable methods of that class.

For an example,

MyRTPIServiceClient client = new MyRTPIServiceClient();
client.GetRealTimeStopDataCompleted += new EventHandler<GetRealTimeStopDataCompletedEventArgs>(client_GetRealTimeStopDataCompleted);
client.GetRealTimeStopDataAsync();

Also, define a event handler of client_GetRealTimeStopDataCompleted

Good luck !!

Upvotes: 0

Related Questions