none
利用web service 生产xml文件 RRS feed

  • 问题

  • 我用下面的代码在本机测试能够生成xml文件,返回"Y".但是我把Web service放在服务器上返回的是"N".我的服务器是windows2008,IIS 7.0  请大家帮忙看下是什么原因引起的。

    using System;
    using System.Data;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Text;
    using System.Xml;
    using System.Data.Sql;
    using System.Data.SqlClient;
    using System.Configuration;
    using System.IO;
    using System.Web;
    using System.Web.Services;
    
    namespace WebApplication1
    {
        /// <summary>
        /// Summary description for WebService2
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
    
        public class WebService2 : System.Web.Services.WebService
        {
    
            [WebMethod]
            public string HelloWorld()
            {
                return "Hello World";
            }
    
            [WebMethod]
            public string XmlEDI(string OrderNumber, string QuotationNo)
            {
    
    
                SqlConnection conn = new SqlConnection();
    
                // conn.ConnectionString = "Provider=SQLOLEDB;Server=(local);database=SchneiderEDI;Integrated Security=SSPI";
    
                //conn.ConnectionString = "Data Source=10.210.1.21;Initial Catalog=HAG_CWH_21test;Persist Security Info=True;User ID=HAG_CWH;Password=HAG_CWH";
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["EDIconn"].ConnectionString;
                SqlCommand cmd = conn.CreateCommand();
                SqlCommand cmdItem = conn.CreateCommand();
                //string OrderNo = Dts.Variables["OrderNo"].Value.ToString();
                //string OrderNo = "0020239485";
                //string strResult;
    
                cmd.CommandText = "SELECT Header.BSTKD_E,Header.VBELN,Convert(Varchar(8),Header.BSTDK,112) as BSTDK,Header.KUNNR,Header.KGNNR,Header.QTFLAG FROM V_EDI_HEAD_Upload as Header  where Header.BSTKD_E = '" + OrderNumber + "' and Header.VBELN = '" + QuotationNo + "' for xml auto,ELEMENTS";
                cmdItem.CommandText = "Select ITEM.POSNR,ITEM.VTEXT,ITEM.MATNR,ITEM.KWMENG,Convert(Varchar(8),ITEM.EDATU,112) as EDATU from V_EDI_DETAIL_Upload as ITEM where ITEM.BSTKD_E = '" + OrderNumber + "'and ITEM.VBELN = '" + QuotationNo + "' for xml auto,ELEMENTS";
                conn.Open();
                string sqlstring = "select count(*) from V_EDI_HEAD_Upload where BSTKD_E = '" + OrderNumber + "' and VBELN = '" + QuotationNo + "'";
                SqlCommand command = new SqlCommand(sqlstring, conn);
                //conn.Open();
                //SqlDataReader reader = command.ExecuteReader();
                int i = Convert.ToInt32(command.ExecuteScalar());
                // Int32 i = (Int32) command.ExecuteScalar();
                // command.Dispose();
    
                if (i > 0)
                {
                    try
                    {
                        XmlReader xrd = cmd.ExecuteXmlReader();
                        XmlReader xrdItem = cmdItem.ExecuteXmlReader();
    
    
                        XmlDocument xmldom = new XmlDocument();
    
                        XmlDeclaration declaration = xmldom.CreateXmlDeclaration("1.0", "UTF-8", null);
    
                        xmldom.AppendChild(declaration);
    
                        XmlElement root = xmldom.CreateElement("ns1:Z_MT_SD_009_SO_CREATION", "http://schneider-distributor.com/");
    
    
    
    
                        xmldom.AppendChild(root);
    
                        XmlElement node = null;
    
                        XmlElement child = null;
    
                        XmlText text = null;
    
                        while (xrd.Read())
                        {
                            if (xrd.NodeType == XmlNodeType.Element)
                            {
                                if (xrd.Name.Equals("Header"))
                                {
                                    node = xmldom.CreateElement(xrd.Name);
    
                                    root.AppendChild(node);
                                }
                                else
                                {
                                    child = xmldom.CreateElement(xrd.Name);
    
                                    node.AppendChild(child);
                                }
                            }
    
                            if (xrd.NodeType == XmlNodeType.Text)
                            {
                                text = xmldom.CreateTextNode(xrd.Value);
    
                                child.AppendChild(text);
                            }
                        }
    
                        //--------------
    
                        while (xrdItem.Read())
                        {
                            if (xrdItem.NodeType == XmlNodeType.Element)
                            {
                                if (xrdItem.Name.Equals("ITEM"))
                                {
                                    node = xmldom.CreateElement(xrdItem.Name);
    
                                    root.AppendChild(node);
                                }
                                else
                                {
                                    child = xmldom.CreateElement(xrdItem.Name);
    
                                    node.AppendChild(child);
                                }
                            }
    
                            if (xrdItem.NodeType == XmlNodeType.Text)
                            {
                                text = xmldom.CreateTextNode(xrdItem.Value);
    
                                child.AppendChild(text);
                            }
                        }
    
                        //--------------
    
                        //string _Service = @"//10.210.1.66";
                        ////string _Path = "z_mi_sd_009_so_creation_file";
                        //string _Path = "upload_backup";
                        //ConnectLan(_Service, "EDI", "p@ssw0rd");
    
                        //DirectoryInfo _Direct = new DirectoryInfo(_Service + "//" + _Path);
                           DirectoryInfo _Direct = new DirectoryInfo(@"D:\");
                        //string ServerFolder = @"use Z: \\10.210.1.66\z_mi_sd_009_so_creation_file";
                        //System.Diagnostics.Process.Start("net", @ServerFolder);
                        string newfilename = _Direct + "//SD009" + "_" + DateTime.Now.Ticks.ToString() + ".xml";
                        //string outputFileName = "@" + newfilename; // ".xml" will be appended.
                        xmldom.Save(newfilename);
    
                        xrd.Close();
    
                        conn.Close();
    
                        conn.Dispose();
    
                        cmd.Dispose();
    
    
                       // CreateSqlLog("成功发送确认报价单: '" + QuotationNo + "'& 采购订单: '" + OrderNumber + "'", newfilename);
                        return "Y";
    
                    }
                    catch
                    {
                       // CreateSqlLog("发送确认报价单失败: '" + QuotationNo + "'& 采购订单: '" + OrderNumber + "'", "");
                        return "N";
                    }
    
                }
    
    
                else
                {
                return null;
                }
    
            }
        }
    }
    
    

     

    2011年12月28日 8:28

全部回复