肥皂?从C#windows服务获取信息到Web服务或WCF服务 [英] SOAP? Getting information from a C# windows service to a Web service or WCF Service

查看:85
本文介绍了肥皂?从C#windows服务获取信息到Web服务或WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以将数据从Windows服务传输到Web服务或wcf服务。我读过不同的文章,让我认为这可能是使用SOAP完成的。我从来没有尝试过让2个应用程序进行通信,所以任何帮助都会受到赞赏提前致谢。



C#console app ....



 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text;
使用 System.Web;
使用系统;
使用 System.IO;
使用 System.Runtime.Remoting;
使用 System.Runtime.Remoting.Channels;
使用 System.Net;
使用 System.Diagnostics;
使用 System.Configuration.Assemblies;



命名空间 Soap_Test
{
class 计划
{
静态 void Main( string [] args)
{
string name = Dustin;

Aim.NameRequest request = new Aim.NameRequest();
Aim.ServiceSoapClient serv = new Aim.ServiceSoapClient();

Aim.NameResponse test = serv.Name(request);

return name(test);

}


}
}





Wcf服务



 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.Services;

[WebService(Namespace = http://aim.oscautomation.com)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 允许要使用ASP.NET AJAX从脚本调用此Web服务,请取消注释以下行。
// [System.Web.Script.Services.ScriptService]

public class 服务:System.Web.Services.WebService
{
public 服务(){

// 如果使用设计的组件,则取消注释以下行
// 的InitializeComponent();
}

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

[WebMethod]
public string 名称(){
return 名称 ;
}
}





仍然没有完全理解一切的整个请求部分。到目前为止,谢谢你的帮助。请告诉我我错过的内容。

解决方案

您好,



您可以添加对来自Windows服务的wcf服务。

如果您使用的是Visual Studio,您可以从SOAP协议中抽象出来,因为一切都是为您设置的。



祝您好运!


一旦您完成了服务,您就可以创建一个项目(它可以是一个Web API)来调用它,然后在REST中发送它



如果你去webApi

将服务添加到你的项目中,并在方法内的控制器中执行以下操作:

 yourService.yourMethodRequest request =  new  yourService.yourMethodRequest(); 
yourService.ServiceClient serv = new yourService.ServiceClient();

yourService.yourMethodResponse test = serv.yourMethod(request);

return 查看(测试);





这将返回它像json或XML一样在REST中调用



如果你想去WCF解决方案,请阅读使用不同绑定在多个应用程序中重用WCF服务 [ ^ ]







希望它帮助


I would like to know if it is possible to transfer data from a windows service to either a web service or a wcf service. I have read different article that lead me to think that this might could be done using SOAP. I have never attempted to make 2 applications communicate before so any help is appreciated. Thanks in Advance.

C# 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;



namespace Soap_Test
{
    class Program
    {
        static void Main(string[] args)
        {
            string name = "Dustin";

            Aim.NameRequest request = new Aim.NameRequest();
            Aim.ServiceSoapClient serv = new Aim.ServiceSoapClient();

            Aim.NameResponse test = serv.Name(request);

            return name(test);
           
        }
      

        }
    }



Wcf Service

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

[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 HelloWorld() {
        return "Hello World";
    }
        
        [WebMethod]
        public string Name()  {      
            return "Name";
        }
    }



Still not completely understanding the whole request part of everything. Thank you so far for your help. Please let me know what I am missing.

解决方案

Hello,

You can add a reference to the wcf services from the windows service.
If you''re using Visual Studio you can abstract from SOAP protocol, because everything is set for you.

Good luck!


once you have your service up you can create a project (it could be a web API) that calls it and then send it in REST

If you go for the webApi
add the service to your project, and in the controller inside the method do this:

yourService.yourMethodRequest request = new yourService.yourMethodRequest();
           yourService.ServiceClient serv = new yourService.ServiceClient();

            yourService.yourMethodResponse test = serv.yourMethod(request);

           return View(test);



This will return it like json or XML to be call in REST

if you want to go for the WCF solution read this Reusing WCF Service Across Several Applications using Different Bindings[^]



Hope it helps


这篇关于肥皂?从C#windows服务获取信息到Web服务或WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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