Silverlight到Web服务不起作用? [英] Silverlight to Web Service not working?

查看:96
本文介绍了Silverlight到Web服务不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我有一个简单的Silverlight Web应用程序表单,我创建该表单是为了测试为更大的项目设置的Web服务.此表单基本上是采用名字,姓氏和中间名的文本框,然后单击按钮,代码便传递到服务器上的Web服务,该服务以pdf形式打印,保存到磁盘,然后通过电子邮件发送它.

我已经编写了所有代码,没有收到任何错误,但是没有用.没有文件被保存,也没有电子邮件被发送.

这是MainPage.xaml.cs中的代码:

Hey everyone.

I have a simple Silverlight web app form I created to test a web service I have set up for a bigger project. This form is basically textboxes that take First Name, Last Name, and Middle Name, and on button click, the code gets passed on to the web service on the server, which prints them in a pdf form, saves it to disk, then emails it.

I’ve written all the code, I don’t get any errors, but it’s not working. No file gets saved and no email gets sent.

Here’s the code from the 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;

        }
    }
}




这是我的网络服务中的代码:




And here’s the code from my web service:

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!");
            }

        }
    }
}



我无法确定设置的问题.



I can’t tell what is wrong with what I have set up.

推荐答案

要调试该应用程序,可以在MainPage.xaml中编写try .. catch块. cs

To debug the application, you can write try.. catch block in MainPage.xaml.cs

private void button1_Click(object sender, RoutedEventArgs e)
       {
         try
         {
           ServiceReference1.newpdfRequestBody proxy = new ServiceReference1.newpdfRequestBody();
           proxy._1_FirstName = textBox1.Text;
           proxy._1_lastName = textBox2.Text;
           proxy._1_middlename = textBox3.Text;
         }
         catch (Exception ex)
         {....}
       }


我看不到您实际调用该Web服务的任何地方.
I don''t see anywhere that you actually call the webservice.


这篇关于Silverlight到Web服务不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆