×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Registered User
    Join Date
    Oct 2010
    Location
    Trivandrum ,Kerala
    Posts
    139

    SOAP web service request with credentials for Windows Phone 7

    I want to develop a windowsphone application which has to send a SOAP request with credentials to a web-service ,the trasport protocol has to be XML and JSON. I just want to know how to construct the SOAP request, send it, and get the result from the service.
    sreerajvr

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

    Re: SOAP web service request with credentials for Windows Phone 7

    Have you tried anything? Visual Studio is pretty good at generating proxy classes using the WSDL ("Add Service Reference" or something similar for the project).

  3. #3
    Nokia Developer Moderator
    Join Date
    Feb 2011
    Location
    Portugal
    Posts
    946

    Re: SOAP web service request with credentials for Windows Phone 7

    Quote Originally Posted by sreerajvr View Post
    I want to develop a windowsphone application which has to send a SOAP request with credentials to a web-service ,the trasport protocol has to be XML and JSON. I just want to know how to construct the SOAP request, send it, and get the result from the service.
    You have an option on Visual Studio do add a Web Reference. You should start there. Mind that in some cases there have been reported issues with adding a Web Reference directly to a Windows Phone project, so you can try an alternative route that is to add a Windows Phone Class Library project and add your web reference there. Then on your main project add a reference to the new project (you can add by assembly or by project in solution) and give it a go.

  4. #4
    Registered User
    Join Date
    Oct 2010
    Location
    Trivandrum ,Kerala
    Posts
    139

    Re: SOAP web service request with credentials for Windows Phone 7

    I have added "Service references" to generate Proxy classes for webservice that I want to consume .I got all Proxy classes from webservice(WSDL) .So far everything is fine,but don't know how to send the SOAP request to the server.
    sreerajvr

  5. #5
    Nokia Developer Moderator
    Join Date
    Feb 2011
    Location
    Portugal
    Posts
    946

    Re: SOAP web service request with credentials for Windows Phone 7

    Quote Originally Posted by sreerajvr View Post
    I have added "Service references" to generate Proxy classes for webservice that I want to consume .I got all Proxy classes from webservice(WSDL) .So far everything is fine,but don't know how to send the SOAP request to the server.
    You just create an instance of the service and invoke the methods of it.

    Take a look at the Weather Forecast Sample sample project here:
    http://msdn.microsoft.com/en-us/libr...=VS.92%29.aspx

    Direct Links to source code:

    VB.NET: http://go.microsoft.com/fwlink/?LinkId=223474
    C#: http://go.microsoft.com/fwlink/?LinkId=219075

  6. #6
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,692

    Re: SOAP web service request with credentials for Windows Phone 7

    The free e-book (Petzold: Programming Windows Phone 7) also contains a tiny example, just search for SOAP in it. Starts around page 95.

  7. #7
    Registered User
    Join Date
    Oct 2010
    Location
    Trivandrum ,Kerala
    Posts
    139

    Re: SOAP web service request with credentials for Windows Phone 7

    Thank you so much for your reply!!
    I have referred the book.I solved all issues in spite of SOAP header authentication.Have any idea on how to sent SOAP header credentials?
    sreerajvr

  8. #8
    Nokia Developer Moderator
    Join Date
    Feb 2011
    Location
    Portugal
    Posts
    946

    Re: SOAP web service request with credentials for Windows Phone 7

    Quote Originally Posted by sreerajvr View Post
    Thank you so much for your reply!!
    I have referred the book.I solved all issues in spite of SOAP header authentication.Have any idea on how to sent SOAP header credentials?
    You need to add custom headers to your soap message I believe. In theory, depending on the webservice you are accessing, there should be a proxy class for the authentication header created when you created the webservice reference. If thats the sase, the class will have a Username and Password properties. If you dont have that proxy class generated for you you will need to add custom headers to the request object.

  9. #9
    Registered User
    Join Date
    Oct 2010
    Location
    Trivandrum ,Kerala
    Posts
    139

    Re: SOAP web service request with credentials for Windows Phone 7

    Thank you for your Help!!

    I want to post my request to the web service. How to implement?

    This is my code
    string soap =@"<?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>
    <Register xmlns=""http://tempuri.org/"">
    <id>123</id>
    <data1>string</data1>
    </Register>
    </soap:Body>
    </soap:Envelope>";
    HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://localhost/WebServices/CustomerWebService.asmx");
    req.ContentType = "text/xml;charset=\"utf-8\"";
    req.Accept = "text/xml";
    req.Method = "POST";
    req.Headers["Name"] = "sreerajvr";
    req.Headers["Password"] = "1234";
    req.BeginGetRequestStream(searchOnlineRequest, req);


    Using REST webservice.I got the result with the following code

    // start loading XML-data
    public MainPage()
    {
    InitializeComponent();
    WebClient downloader = new WebClient();
    Uri uri = new Uri("http://192.168.1.12/ws/sreeraj.xml", UriKind.Absolute);
    downloader.DownloadStringCompleted += new DownloadStringCompletedEventHandler(EmployeesDownloaded);
    downloader.DownloadStringAsync(uri);
    }

    void EmployeesDownloaded(object sender, DownloadStringCompletedEventArgs e)
    {
    if (e.Result == null || e.Error != null)
    {
    MessageBox.Show("There was an error downloading the XML-file!");
    }
    else
    {
    MessageBox.Show(e.Result);
    }
    }
    Last edited by sreerajvr; 2012-03-21 at 12:23.
    sreerajvr

  10. #10
    Nokia Developer Moderator
    Join Date
    Feb 2011
    Location
    Portugal
    Posts
    946

    Re: SOAP web service request with credentials for Windows Phone 7

    I never tried to access webservices the way you are trying to do. I usually work with the Add Service Reference on the WP project and go from there.

    Are these services done by you or by someone else? Any special reason on why you cant use WCF?

  11. #11
    Registered User
    Join Date
    Oct 2010
    Location
    Trivandrum ,Kerala
    Posts
    139

    Re: SOAP web service request with credentials for Windows Phone 7

    No,the sevices provided by someone else;their sevice is a SOAP and the all transations between the program and the webservice is in XML format.However I added WSDL via 'Add reference Service' and got proxy classes and structures.For accessing this classes in my program added 'webservice' by 'using direction'(eg: using myprogram.MsrMapsService) .Now I am wondering how to send the credentials to the webservice.
    Last edited by sreerajvr; 2012-03-22 at 10:48.
    sreerajvr

  12. #12
    Nokia Developer Moderator
    Join Date
    Feb 2011
    Location
    Portugal
    Posts
    946

    Re: SOAP web service request with credentials for Windows Phone 7

    Quote Originally Posted by sreerajvr View Post
    No,the sevices provided by someone else;their sevice is a SOAP and the all transations between the program and the webservice is in XML format.However I added WSDL via 'Add reference Service' and got proxy classes and structures.For accessing this classes in my program added 'webservice' by 'using direction'(eg: using myprogram.MsrMapsService) .Now I am wondering how to send the credentials to the webservice.
    Have you tried this?

    service.ClientCredentials.UserName.UserName = "yourusername"
    service.ClientCredentials.UserName.Password = "yourpassword"

    service is the object with the instance of a service.

    Example (VB):


    Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
    Dim service As New ServiceReference1.Service1Client

    service.ClientCredentials.UserName.UserName = "blabla"
    service.ClientCredentials.UserName.Password = "bleble"


    service.GetDataAsync(2012)
    AddHandler service.GetDataCompleted, AddressOf teste


    End Sub

    Private Sub teste(sender As Object, e As ServiceReference1.GetDataCompletedEventArgs)
    TextBox1.Text = e.Result
    End Sub

  13. #13
    Registered User
    Join Date
    Oct 2010
    Location
    Trivandrum ,Kerala
    Posts
    139

    Re: SOAP web service request with credentials for Windows Phone 7

    I have done a Dictionary app( using SOAP web service)and works fine when the WSDL is in asmx format.
    (WSDL: http://services.aonaware.com/DictSer...ctService.asmx )
    but the problem comes when I actually try with the other webservices(other than asmx).. Any idea what could be going wrong?

    Code snippets

    XAML
    <phone:PhoneApplicationPage
    x:Class="AonawareDictionaryClient.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns: phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell=" clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:toolkit=" clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" d : DesignWidth="480" d : DesignHeight="768"
    FontFamily=" {StaticResource PhoneFontFamilyNormal} "
    FontSize=" {StaticResource PhoneFontSizeNormal} "
    Foreground=" {StaticResource PhoneForegroundBrush} "
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    <Grid.RowDefinitions>
    <RowDefinition Height="Auto"/>
    <RowDefinition Height="Auto"/>
    <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <toolkit:ListPicker Grid.Row="0" x:Name="listPickerDictionaryList"
    Header="Select Dictionary :">
    </toolkit:ListPicker>

    <Grid Grid.Row="1" Margin="0,5,0,0">
    <Grid.ColumnDefinitions>
    <ColumnDefinition Width="*"/>
    <ColumnDefinition Width="Auto" />
    </Grid.ColumnDefinitions>

    <TextBox x:Name="txtboxInputWord" Grid.Column="0" GotFocus="OnTextboxInputWordGotFocus" />
    <Button x:Name="btnGo" Grid.Column="1" Click="OnButtonGoClick" >
    <Button.Content>
    <Image Source="/images/button-go.png"/>
    </Button.Content>
    </Button>
    </Grid>

    <ScrollViewer Grid.Row="2" x:Name="scrollViewer">
    <TextBlock Margin="12,5,12,5" x:Name="txtBlockWordMeaning" HorizontalAlignment="Stretch"
    VerticalAlignment="Stretch" TextWrapping="Wrap"
    FontSize="26" />
    </ScrollViewer>
    </Grid>

    </phone:PhoneApplicationPage>

    C# code

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Microsoft.Phone.Controls;
    using AonawareDictionaryClient.AonawareDictionaryService;
    using System.IO.IsolatedStorage;

    namespace AonawareDictionaryClient
    {
    public partial class MainPage : PhoneApplicationPage
    {
    // Constructor
    public MainPage()
    {
    InitializeComponent();
    }
    DictServiceSoapClient DictSvcClient = null;

    private DictServiceSoapClient GetDictServiceSoapClient()
    {
    if (null == DictSvcClient)
    {
    DictSvcClient = new DictServiceSoapClient();
    }

    return DictSvcClient;
    }

    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
    DictServiceSoapClient client = GetDictServiceSoapClient();

    client.DictionaryListCompleted += new EventHandler<DictionaryListCompletedEventArgs>(OnGetDictionaryListCompleted);

    client.DictionaryListAsync();

    base.OnNavigatedTo(e);
    }

    void OnGetDictionaryListCompleted(object sender, DictionaryListCompletedEventArgs e)
    {
    IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
    Dictionary[] listOfDictionaries;

    if (e.Error == null)
    {
    listOfDictionaries = e.Result;
    PopulateListPicker(listOfDictionaries, settings);
    }
    else if (settings.Contains("SavedDictionaryList"))
    {
    listOfDictionaries = settings["SavedDictionaryList"] as Dictionary[];
    PopulateListPicker(listOfDictionaries, settings);
    }
    else
    {
    MessageBoxResult res = MessageBox.Show("An error occured while retrieving dictionary list, do you want to try again?", "Error", MessageBoxButton.OKCancel);

    if (MessageBoxResult.OK == res)
    {
    GetDictServiceSoapClient().DictionaryListAsync();
    }
    }

    settings.Save();
    }

    void PopulateListPicker(Dictionary[] listOfDictionaries, IsolatedStorageSettings settings)
    {
    listPickerDictionaryList.Items.Clear();

    foreach (Dictionary dictionary in listOfDictionaries)
    {
    listPickerDictionaryList.Items.Add(dictionary.Name);
    }

    settings["SavedDictionaryList"] = listOfDictionaries;

    string savedDictionaryName;
    if (settings.Contains("SavedDictionary"))
    {
    savedDictionaryName = settings["SavedDictionary"] as string;
    }
    else
    {
    savedDictionaryName = "WordNet (r) 2.0"; //default dictionary, wordnet
    }

    foreach (string dictName in listPickerDictionaryList.Items)
    {
    if (dictName == savedDictionaryName)
    {
    listPickerDictionaryList.SelectedItem = dictName;
    break;
    }
    }

    settings["SavedDictionary"] = listPickerDictionaryList.SelectedItem as string;
    }

    private void OnButtonGoClick(object sender, RoutedEventArgs e)
    {
    txtBlockWordMeaning.Text = "Please wait..";

    IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;

    if (txtboxInputWord.Text.Trim().Length <= 0)
    {
    MessageBox.Show("Please enter a word in the textbox and press 'Go'");
    }
    else
    {
    Dictionary[] listOfDictionaries = settings["SavedDictionaryList"] as Dictionary[];
    string selectedDictionary = listPickerDictionaryList.SelectedItem.ToString();

    string dictId = "wn"; //default dictionary is wordnet (wn is the dict id)

    foreach (Dictionary dict in listOfDictionaries)
    {
    if (dict.Name == selectedDictionary)
    {
    dictId = dict.Id;
    break;
    }
    }

    DictServiceSoapClient client = GetDictServiceSoapClient();

    client.DefineInDictCompleted += new EventHandler<DefineInDictCompletedEventArgs>(OnDefineInDictCompleted);
    client.DefineInDictAsync(dictId, txtboxInputWord.Text.Trim());
    }
    }

    void OnDefineInDictCompleted(object sender, DefineInDictCompletedEventArgs e)
    {
    WordDefinition wd = e.Result;

    scrollViewer.ScrollToVerticalOffset(0.0f);

    if (wd == null || e.Error != null || wd.Definitions.Length == 0)
    {
    txtBlockWordMeaning.Text = String.Format("No definitions were found for '{0}' in '{1}'", txtboxInputWord.Text.Trim(), listPickerDictionaryList.SelectedItem.ToString().Trim());
    }
    else
    {
    foreach (Definition def in wd.Definitions)
    {
    string str = def.WordDefinition;
    str = str.Replace(" ", " "); //some formatting
    txtBlockWordMeaning.Text = str;
    }
    }
    }

    protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
    {
    IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;

    settings["SavedDictionary"] = listPickerDictionaryList.SelectedItem as string;

    settings.Save();

    base.OnNavigatingFrom(e);
    }

    private void OnTextboxInputWordGotFocus(object sender, RoutedEventArgs e)
    {
    TextBox txtbox = sender as TextBox;

    if (txtbox.Text.Trim().Length > 0)
    {
    txtbox.SelectionStart = 0;
    txtbox.SelectionLength = txtbox.Text.Length;
    }
    }
    }
    }
    Last edited by sreerajvr; 2012-03-28 at 09:57.
    sreerajvr

  14. #14
    Nokia Developer Moderator
    Join Date
    Feb 2011
    Location
    Portugal
    Posts
    946

    Re: SOAP web service request with credentials for Windows Phone 7

    Quote Originally Posted by sreerajvr View Post
    I have done a Dictionary app( using SOAP web service)and works fine when the WSDL is in asmx format.
    (WSDL: http://services.aonaware.com/DictSer...ctService.asmx )
    but the problem comes when I actually try with the other webservices(other than asmx).. Any idea what could be going wrong?

    Code snippets
    I'm curious. When you say that its works with asmx but not with others, are you trying to use the same service reference to access other services? When you add a deference to the project using a service reference, visual studio basically generates among other things a proxy class for each type on the service and creates a proxy class to access the methods of the service. You can move your service to another place and even rename it as long as the signature is the same. But if you try to access a different type of service, even if the signature is the same, you will run into problems.

    In other words you need to add a reference to each service you want to access. Unless all services are based on the same signature / type (even if you change addresses) you will need to have different service references.

    If you want to keep things mapped to the same proxy types / classes then you will need to create a class library with the types and tell Visual Studio to map to an existent type. You can do that by right click on the service reference and select "configure service reference", select "reuse types in specified referenced assemblies" and that way you will be able to map all your services to the same classes. You still need to have different references.

    Hope this is what you are looking for. If not, please provide more details.

  15. #15
    Registered User
    Join Date
    Oct 2010
    Location
    Trivandrum ,Kerala
    Posts
    139

    Re: SOAP web service request with credentials for Windows Phone 7

    Till now,I have developed two test applications using SOAP Webservice and both of the WSDL files are in '.asmx' format.Unfortunately my original WSDL does not have a .asmx extension.How do I solve this?
    sreerajvr

Similar Threads

  1. Request to get nokia windows phone device.
    By dheeraj_pk@hotmail.com in forum Windows Phone General
    Replies: 7
    Last Post: 2012-03-15, 14:51
  2. Replies: 2
    Last Post: 2010-10-29, 11:32
  3. SOAP request
    By mastermindcoders in forum Symbian Networking & Messaging (Closed)
    Replies: 2
    Last Post: 2010-06-14, 15:47
  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
  •  
×