C#控制台应用程序将值发送到Web服务 [英] C# Console application to send values to a Web Service

查看:112
本文介绍了C#控制台应用程序将值发送到Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Web Services的新手,现在我了解如何通过在我的控制台应用程序中添加Web服务引用并调用Web服务的方法,将信息从Web服务提取到我的控制台应用程序。但我的主要目标是从控制台应用程序向Web服务发送信息。如何才能做到这一点?这是我到目前为止的代码(从Web服务调用方法)。



我的控制台应用程序......



I am new to Web Services, and I now understand how to pull information from the web service to my console application by adding the web service reference in my console application and calling the web service''s methods. But my main goal is to send information to the web service from the the console application. How can this be done? Here is my code so far (calling the methods from the web service).

My console app...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System;
using System.IO;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Net;
using System.Diagnostics;
using System.Configuration.Assemblies;
using Soap_Test.aim;
using System.ServiceModel;
using System.Windows.Forms;
using System.Web.Services.Protocols;



namespace Soap_Test
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {

            Service aim = new Service();
            string result = aim.WORD();
            Console.WriteLine(result);
            Console.ReadLine();

                

        }


        }
    }





和我的网络服务....





and my web service....

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.ServiceModel;


[WebService(Namespace = "http://aim.oscautomation.com")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]

public class Service : System.Web.Services.WebService
{
    public Service () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
       
    }

    [WebMethod]
    public string WORD()
    {

        return "Work";
    }

    [WebMethod]
    public string HelloWorld() {
        return "Hello World";
    }
        
        [WebMethod]
        public string Name()  {      
            return "Name";
        }

        [WebMethod]
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }


    }





先谢谢!



Thanks in Advance!

推荐答案

问题是:在您的客户端代码中,您从哪里获得类型服务,它是什么?您是否添加了Web引用?



无论如何,这是一个简短的教程: http://www.c-sharpcorner.com/UploadFile/718fc8/consuming-web-service-in-console-application/ [< a href =http://www.c-sharpcorner.com/UploadFile/718fc8/consuming-web-service-in-console-application/\"target =_ blanktitle =New Window> ^ ]。



-SA
The question is: in your client code, where did you get the type Service, what is it? Did you add a Web reference?

Anyway, this is a short tutorial: http://www.c-sharpcorner.com/UploadFile/718fc8/consuming-web-service-in-console-application/[^].

—SA


这篇关于C#控制台应用程序将值发送到Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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