使用基于Soap的XML服务

时间:2015-04-30 18:10:03

标签: xml web-services wcf c#-4.0 soap

我正在尝试通过基于SOAP的服务传递XML。这里我直接从我的存储过程创建我的xml并访问返回的xml。 获取下面给出的XML的代码:

public XmlDataDocument GetData()
{
    string msg = string.Empty;

    SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalConnection"].ToString());

    using (SqlCommand command = connection.CreateCommand())
    {
        command.CommandType = CommandType.StoredProcedure;
        command.CommandText = "usp_YoOne_Request";
        connection.Open();
        command.CommandTimeout = 600;

        XmlReader reader = command.ExecuteXmlReader();

        XmlDataDocument xml = new XmlDataDocument();
        xml.Load(reader);
        connection.Close();

        return xml;
    }

}

这很好用,正在读取XML并返回xml。但是当我尝试在我的测试应用程序中使用此服务时,它无法正常工作。我用来使用xml的代码。

更新:正如您所看到的,我尝试过的所有其他方式对我来说都不起作用。关于端点,它确实从服务调用GetData()方法并返回xmldocument而没有错误。在调试期间它确实显示xml是正确的。唯一的问题在于使用返回的xml。

        class Class1
        {

            static void Main(string[] args)
            {
                BankOperatorsYoClient proxy = new BankOperatorsYoClient();

                XmlDataDocument addResult = proxy.GetData(); // Doest not allow me to call my function here 
               // error: Cannot implicitly convert object[] to System.Xml.XmlDataDocument

               var addResult = proxy.GetData(); //Does not work and gives error
              //Additional information: An error occurred while receiving
// the HTTP response to http://localhost:57881/BankoService.svc. This could be 
//due to the service endpoint binding not using the HTTP protocol. This could 
//also be due to an HTTP request context being aborted by the server (possibly
 //due to the service shutting down). See server logs for more details.

             object[] addResult = proxy.PutData(); // Gives the same error as above

                Console.WriteLine("Result of Add Operation");

                Console.WriteLine(addResult);

                Console.ReadKey(true);
            }

        }

我不明白我做错了什么。如果有人可以帮我这个或者可以告诉我我做错了什么。我在谷歌搜索解决方案但无法识别此代码的问题。

0 个答案:

没有答案