4

I have to use webservices (WSDL) on a Windows Phone 8 App but it doesn't work in VS2012.

For example :

http://chennaiemergency.co.in/sree/s2.php?wsdl

  1. Right click on the project > Add Service reference
  2. Paste the URL in the Address textBox
  3. Click on the "Go" button
  4. the service appears with all operations
  5. click on "ok"

The service is added but there is nothing about my operations in the reference.cs...

Are there other ways to use my wsdl?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
monstergold
  • 755
  • 1
  • 9
  • 24

1 Answers1

4

The best way I found for this problem is to send manually the SOAP request. SOAP and wsdl are not very compatible with WP. If you have the choice, maybe choose a WCF for your web services. My code for the soap request in a Windows Form Application (in a WP project, you have to use asynchronous method -> beginGetRequestStream() & beginGetResponse() . There are a lot of documentation on the msdn about this) :

        // Building of my XML 
        XNamespace env = "http://schemas.xmlsoap.org/soap/envelope/";
        XNamespace xsd = "http://www.w3.org/2001/XMLSchema";
        XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance";
        XNamespace enc = "http://schemas.xmlsoap.org/soap/encoding/";
        XNamespace typens = "urn:...";
        XNamespace xsiType = "xsd:string";
        XElement soapEnv = new XElement(env + "Envelope",
            new XAttribute(XNamespace.Xmlns + "SOAP-ENV",env.NamespaceName),
            new XAttribute(XNamespace.Xmlns + "xsd", xsd.NamespaceName),
            new XAttribute(XNamespace.Xmlns + "xsi", xsi.NamespaceName),
            new XElement(env + "Body",
                new XAttribute(env + "encodingStyle",enc.NamespaceName),
                    new XElement(typens + "MethodName",
                        new XAttribute(XNamespace.Xmlns + "typens",typens.NamespaceName),
                        new XElement("elementName",
                            new XAttribute(xsi + "type",xsiType.NamespaceName), "...value"),
                        new XElement("elementName",
                            new XAttribute(xsi + "type",xsiType.NamespaceName),"...value"),
                        new XElement("elementName",
                            new XAttribute(xsi + "type",xsiType.NamespaceName),"...value")
        )));

        // HTTPWEBREQUEST
        HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("...url...");
        webRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
        webRequest.Method = "POST";
        webRequest.KeepAlive = false;
        webRequest.ContentType = "text/xml; charset=utf-8";
        webRequest.CookieContainer = new CookieContainer();

        webRequest.Headers.Add("SOAPAction", "...webservice link...");
        webRequest.ProtocolVersion = new Version(1,1);
        webRequest.Timeout = 1000;


        using (StreamWriter stream = new StreamWriter(webRequest.GetRequestStream()))
        { 
            stream.Write(soapEnv); 
            stream.Flush();
            stream.Close();            
        }


        using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse())
        {
            using (StreamReader responseReader = new StreamReader(webResponse.GetResponseStream()))
            {
                if (responseReader != null)
                {
                    .....code....
                    webResponse.Close();
                }
            }            
        }
monstergold
  • 755
  • 1
  • 9
  • 24