我有一个简单的Silverlight Web应用程序表单,用于测试我为更大的项目设置的Web服务。此表单基本上是带有名字,姓氏和中间名称的文本框,按下按钮,代码将传递到服务器上的Web服务,以pdf格式打印,将其保存到磁盘,然后发送电子邮件它。 我写了所有的代码,我没有得到任何错误,但它没有工作。没有文件被保存,也没有发送电子邮件。 这是MainPage.xaml.cs中的代码:
using System;
using System.Collections.Generic;
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 System.ServiceModel;
using ExampleSilverlightApp.ServiceReference1;
namespace ExampleSilverlightApp
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
ServiceReference1.newpdfRequestBody proxy = new ServiceReference1.newpdfRequestBody();
proxy._1_FirstName = textBox1.Text;
proxy._1_lastName = textBox2.Text;
proxy._1_middlename = textBox3.Text;
}
}
}
以下是我的网络服务代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Text;
using System.IO;
using System.Net.Mail;
using iTextSharp.text;
using iTextSharp.text.pdf;
namespace ExampleSilverlightApp.Web
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class MyWebService : System.Web.Services.WebService
{
[WebMethod]
public void newpdf(string _1_FirstName, string _1_lastName, string _1_middlename)
{
string filename = @"C:\Temp\" + _1_FirstName + _1_lastName + ".pdf";
iTextSharp.text.Document d = new iTextSharp.text.Document(PageSize.A4, 72, 72, 172, 72);
PdfWriter.GetInstance(d, new FileStream(filename, FileMode.Create));
d.Open();
d.Add(new Paragraph(string.Format("First Name:", _1_FirstName)));
d.Add(new Paragraph(string.Format("Last Name:", _1_lastName)));
d.Add(new Paragraph(string.Format("Middle Name:", _1_middlename)));
d.Close();
try
{
MailAddress SendFrom = new MailAddress("t@hotmail.com");
MailAddress SendTo = new MailAddress("tg@gmail.com");
MailMessage MyMessage = new MailMessage(SendFrom, SendTo);
MyMessage.Subject = "new test";
MyMessage.Body = "heres a new test!";
Attachment attachfile = new Attachment(filename);
MyMessage.Attachments.Add(attachfile);
SmtpClient emailClient = new SmtpClient("smtp.live.com");
emailClient.Send(MyMessage);
}
catch (FileNotFoundException)
{
Console.WriteLine("File Lost!");
}
}
}
}
我不知道我的设置有什么问题。
答案 0 :(得分:0)