/// <summary>
/// Summary description for WebService /// </summary>
[WebService(Namespace = 'http://tempuri.org/')]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService {
...
...
}
Define the following two web methods:
[WebMethod]
public bool SaveSignature(string value) {
try {
File.WriteAllText(Server.MapPath('.') +
@'Signature.txt', value);
return true;
} catch (Exception ex) {
return false;
}
}
[WebMethod]
public string GetSignature() {
string fileContents;
fileContents = File.ReadAllText(
Server.MapPath('.') + @'Signature.txt');
return fileContents;
}
The SaveSignature() function saves the values of the signature into a text file. The GetSignature() function reads the content of the text file and returns the content to the caller.
In the Signature project, add a service reference (see Figure 19-75).
Figure 19-75
Click the Discover button and then OK (see Figure 19-76).
Figure 19-76
In Page.xaml.cs, modify the Save button as follows:
//---Save button---
void btnSave_MouseLeftButtonDown(
object sender, MouseButtonEventArgs e) {
EventHandler<Signature.ServiceReference1.SaveSignatureCompletedEventArgs> (ws_SaveSignatureCompleted);
}
Here, you send the signature to the Web service asynchronously. When the Web Service call returns, the ws_SaveSignatureCompleted event handler will be called.
Code the ws_SaveSignatureCompleted event handler as follows:
void ws_SaveSignatureCompleted( object sender,
Signature.ServiceReference1.SaveSignatureCompletedEventArgs e) {
txtStatus.Text = 'Signature sent to WS!';
}
In Page.xaml.cs, code the Load button as follows:
//---Load button---
void btnLoad_MouseLeftButtonDown(
object sender, MouseButtonEventArgs e) {
}
Here, you call the Web service to retrieve the saved signature. When the Web Service call returns, the ws_GetSignatureCompleted event handler will be called.
Code the ws_GetSignatureCompleted event handler as follows:
void ws_GetSignatureCompleted( object sender,
Signature.ServiceReference1.GetSignatureCompletedEventArgs e) {
txtStatus.Text = 'Signature loaded from WS!';
DrawSignature(e.Result);
}
Save the Signature project. In Solution Explorer, right-click on the SignatureWebSite project and select Add Silverlight Link (see Figure 19-77).
Figure 19-77
This causes Visual Studio 2008 to copy the relevant files from the Silverlight project onto the current project. Use the default values populated and click Add (see Figure 19-78).
Figure 19-78
