简体   繁体   English

通过添加服务引用WCF主​​机应用程序?

[英]WCF Host application by add service reference?

I have created a WCF service with some endpoints(with mex endpoint). 我创建了带有某些终结点(带有mex终结点)的WCF服务。 If i create for example a Console Host now and put this in my main: 例如,如果我现在创建一个控制台主机并将其放在我的主目录中:

 ServiceHost host = new ServiceHost(typeof(HelloWorld));

 host.Open();

 Console.WriteLine("The service is ready at!");
 foreach (ServiceEndpoint se in host.Description.Endpoints)
          Console.WriteLine(se.Address.ToString());
      Console.WriteLine("Press <Enter> to stop the service.");
 Console.ReadLine();

// Close the ServiceHost.
host.Close();

Is it possible to generate a app.config on the hostside by adding a service reference, or do i need to create the app config my self and make it similar to the wcf service endpoints? 是否可以通过添加服务引用在主机端生成app.config,还是我需要自行创建应用程序配置并使它类似于wcf服务端点?

Next to this, how is it possible that some other computer on the LAN can access this host? 除此之外,LAN上的其他计算机如何可能访问此主机?

(PS what the heck does this mean: A service may inlcude an mex endpoint, which obtain the ABC's of the service and returns the WSDL. (NOW THE NOT UNDERSTANDABLE PART) After the WSDL is obtained, two artifacts are generated: a proxy class in the language of the project and an app.config file. The proxy class mirrors the signature of the endpoint operations so that client code can simply "call"an endpoint. The proxy interface doesn't have to be identical to the service signature, but the proxy needs to ensure that the message transmitted to the service is precisely what is described by the service contract.(OK WHAT?) (PS到底是什么意思:服务可能包含一个混合端点,该端点获得服务的ABC并返回WSDL。(现在是不可理解的部分)获得WSDL之后,将生成两个工件:代理类用项目和app.config文件的语言表示。代理类反映了端点操作的签名,以便客户端代码可以简单地“调用”端点。代理接口不必与服务签名相同,但是代理服务器需要确保传输到服务的消息正是服务合同所描述的内容。

In your first question I assume you mean "client" when you said "host". 在第一个问题中,我假设您所说的“主持人”是指“客户”。 For this you should put a Uri in the constructor of the ServiceHost in your code. 为此,您应该在代码中将Uri放入ServiceHost的构造函数中。 Eg 例如

ServiceHost host = new ServiceHost(typeof(HelloWorld), new Uri("http://localhost:1234/helloworld", UriKind.Absolute)); 

Then right click your project and go to Debug/Start new instance. 然后右键单击您的项目,然后转到“调试/启动新实例”。 Now your service is up and running under the given Uri. 现在,您的服务已启动并在给定的Uri下运行。 In Visual Studio go to the Debug menu at the top and choose "Detach all". 在Visual Studio中,转到顶部的“调试”菜单,然后选择“全部分离”。 Now your application with the service is still running. 现在,带有该服务的应用程序仍在运行。 You can now go to your client project and add service reference like you're used to. 现在,您可以转到客户项目并像往常一样添加服务参考。 Just fill in the Uri in the Add service reference dialog. 只需在“添加服务参考”对话框中填写Uri。

For your last question. 对于最后一个问题。 It just means that visual studio creates a local file for your service reference and that as a developer you should use that client class as if it is the service itself and that it works :-) 这仅意味着Visual Studio将创建一个本地文件供您的服务参考,并且作为开发人员,您应该使用该客户端类,就好像它是服务本身一样,并且可以正常工作:-)

1) You have to specify endpoints(A-Address,B-Binding,C-contract) in the app.config and this app.config must be with your host app(Your console app in this case) 2) This service can be recognized in the LAN if some client runs visual studio's command prompt and runs this- 1)您必须在app.config中指定终结点(A-Address,B-Binding,C-contract),并且此app.config必须与您的主机应用程序一起使用(在这种情况下,是您的控制台应用程序)2)此服务可以是如果某些客户端运行Visual Studio的命令提示符并运行以下命令,则可以识别LAN

SvcUtil http://localhost/MyService/MyService.svc /out:c:\\Proxy.cs (sample command change various values as per your case...) SvcUtil http://localhost/MyService/MyService.svc /out:c:\\Proxy.cs(示例命令根据您的情况更改各种值...)

Here Proxy.cs contains Proxy class, the client should add this to the solution and calls the method of proxy class, in the same directory where this Proxy.cs exists, you will find 1 .config file, paste this file's contents to the client's app.config. 这里Proxy.cs包含Proxy类,客户端应将其添加到解决方案中并调用Proxy类的方法,在此Proxy.cs所在的目录中,您将找到1个.config文件,并将此文件的内容粘贴到客户端的app.config。 3) MEX endpoint is required to exchange meta information. 3)需要MEX端点来交换元信息。

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

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