Click here to Skip to main content
15,891,905 members
Articles / Programming Languages / C# 4.0

Synchronous Web Service Calls with Silverlight: Dispelling the async-only myth

Rate me:
Please Sign up or sign in to vote.
4.95/5 (47 votes)
16 Nov 2008LGPL311 min read 425.5K   4K   81  
In this article, we look at the asynchronous web service model in Silverlight, and how it can be augmented to allow synchronous web service calls. We also explore efficient channel caching, and asynchronous Silverlight Unit Tests.
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>9.0.30729</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{A2B2D87D-835A-47C0-8834-738B13F19BD1}</ProjectGuid>
    <ProjectTypeGuids>{A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>DanielVaughan.Silverlight.Examples</RootNamespace>
    <AssemblyName>DanielVaughan.Silverlight.Examples</AssemblyName>
    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
    <SilverlightApplication>true</SilverlightApplication>
    <SupportedCultures>
    </SupportedCultures>
    <XapOutputs>true</XapOutputs>
    <GenerateSilverlightManifest>true</GenerateSilverlightManifest>
    <XapFilename>DanielVaughan.Silverlight.Examples.xap</XapFilename>
    <SilverlightManifestTemplate>Properties\AppManifest.xml</SilverlightManifestTemplate>
    <SilverlightAppEntry>DanielVaughan.Silverlight.Examples.App</SilverlightAppEntry>
    <TestPageFileName>TestPage.html</TestPageFileName>
    <CreateTestPage>true</CreateTestPage>
    <ValidateXaml>true</ValidateXaml>
    <ThrowErrorsInValidation>false</ThrowErrorsInValidation>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>Bin\Debug</OutputPath>
    <DefineConstants>DEBUG;TRACE;SILVERLIGHT</DefineConstants>
    <NoStdLib>true</NoStdLib>
    <NoConfig>true</NoConfig>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>Bin\Release</OutputPath>
    <DefineConstants>TRACE;SILVERLIGHT</DefineConstants>
    <NoStdLib>true</NoStdLib>
    <NoConfig>true</NoConfig>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System.Runtime.Serialization" />
    <Reference Include="System.ServiceModel" />
    <Reference Include="System.Windows" />
    <Reference Include="mscorlib" />
    <Reference Include="system" />
    <Reference Include="System.Core" />
    <Reference Include="System.Net" />
    <Reference Include="System.Xml" />
    <Reference Include="System.Windows.Browser" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="App.xaml.cs">
      <DependentUpon>App.xaml</DependentUpon>
    </Compile>
    <Compile Include="Page.xaml.cs">
      <DependentUpon>Page.xaml</DependentUpon>
    </Compile>
    <Compile Include="Properties\AssemblyInfo.cs" />
    <Compile Include="Service References\SimpleServiceReference\Reference.cs">
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
      <DependentUpon>Reference.svcmap</DependentUpon>
    </Compile>
  </ItemGroup>
  <ItemGroup>
    <ApplicationDefinition Include="App.xaml">
      <Generator>MSBuild:MarkupCompilePass1</Generator>
      <SubType>Designer</SubType>
    </ApplicationDefinition>
    <Page Include="Page.xaml">
      <Generator>MSBuild:MarkupCompilePass1</Generator>
      <SubType>Designer</SubType>
    </Page>
  </ItemGroup>
  <ItemGroup>
    <None Include="Properties\AppManifest.xml" />
    <None Include="Service References\SimpleServiceReference\SimpleService.xsd" />
    <None Include="Service References\SimpleServiceReference\SimpleService1.xsd" />
    <Resource Include="Images\OlympicPictogram.png" />
    <Content Include="ServiceReferences.ClientConfig" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\SilverlightCore\SilverlightCore.csproj">
      <Project>{DCAB5FF7-3C9C-43AD-8C70-120361EC8960}</Project>
      <Name>SilverlightCore</Name>
    </ProjectReference>
  </ItemGroup>
  <ItemGroup>
    <WCFMetadata Include="Service References\" />
  </ItemGroup>
  <ItemGroup>
    <WCFMetadataStorage Include="Service References\SimpleServiceReference\" />
  </ItemGroup>
  <ItemGroup>
    <None Include="Service References\SimpleServiceReference\SimpleService.disco" />
    <None Include="Service References\SimpleServiceReference\SimpleService.wsdl" />
    <None Include="Service References\SimpleServiceReference\SimpleService1.wsdl" />
  </ItemGroup>
  <ItemGroup>
    <None Include="Service References\SimpleServiceReference\configuration91.svcinfo" />
  </ItemGroup>
  <ItemGroup>
    <None Include="Service References\SimpleServiceReference\configuration.svcinfo" />
  </ItemGroup>
  <ItemGroup>
    <None Include="Service References\SimpleServiceReference\Reference.svcmap">
      <Generator>WCF Proxy Generator</Generator>
      <LastGenOutput>Reference.cs</LastGenOutput>
    </None>
  </ItemGroup>
  <Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight\v2.0\Microsoft.Silverlight.CSharp.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
  <ProjectExtensions>
    <VisualStudio>
      <FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}">
        <SilverlightProjectProperties />
      </FlavorProperties>
    </VisualStudio>
  </ProjectExtensions>
</Project>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Engineer
Switzerland Switzerland
Daniel is a former senior engineer in Technology and Research at the Office of the CTO at Microsoft, working on next generation systems.

Previously Daniel was a nine-time Microsoft MVP and co-founder of Outcoder, a Swiss software and consulting company.

Daniel is the author of Windows Phone 8 Unleashed and Windows Phone 7.5 Unleashed, both published by SAMS.

Daniel is the developer behind several acclaimed mobile apps including Surfy Browser for Android and Windows Phone. Daniel is the creator of a number of popular open-source projects, most notably Codon.

Would you like Daniel to bring value to your organisation? Please contact

Blog | Twitter


Xamarin Experts
Windows 10 Experts

Comments and Discussions