简体   繁体   English

从WCF Rest服务获取请求

[英]Get Request from WCF Rest service

I added a WCF Library Project(A) to an existing project(B). 我在现有项目(B)中添加了WCF库项目(A)。 Project B initiates the WCF service(A), and can also stop it. 项目B启动WCF服务(A),也可以停止它。

 restSvc = new ServiceHost(typeof(RestServiceSvc.RestEndPoint));
 restSvc.Open();

WCF service (A) has one POST, and I want to pass this information to project (B). WCF服务(A)有一个POST,我想将此信息传递给项目(B)。 project B can be Form Application, but not necessarily. 项目B可以是表单应用程序,但不是必须的。 I have no clue on where to start. 我不知道从哪里开始。 Thank you. 谢谢。

The constructor you chose will always create a new service instance. 您选择的构造函数将始终创建一个新的服务实例。 You cannot influence that. 你不能影响它。 Instead, create your own instance, so you can pass something in when you create it. 而是创建您自己的实例,以便您可以在创建实例时传递一些内容。 It's up to you what you pass. 传递的内容取决于您。 A callback, your Form instance, additional data, anything you want: 回调,您的Form实例,其他数据,所需的任何内容:

var service = new RestServiceSvc.RestEndPoint();

// obviously, you need to implement anything you may want to pass
// you could also pass this in the constructor of your service class
// You can access these properties in your service methods.
service.YourCustomProperty = someDataYouNeed;
service.YourCallBack = () => YourForm.FunctionCall();

restSvc = new ServiceHost(service);
restSvc.Open();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM