动态(运行时)生成WCF服务合同 [英] Dynamic (runtime) Generation of a WCF Service contract

查看:63
本文介绍了动态(运行时)生成WCF服务合同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在学习WCF网络服务,我遇到过这篇文章动态(运行时)生成WCF服务合同,关于动态创建服务合同。我下载了给定的代码并尝试运行它,但它没有成功。它抛出以下错误:



{无法激活所请求的服务,'http://localhost/WcfService1/Service5.svc'。请参阅服务器的诊断跟踪日志以获取更多信息。}



我认为它无法动态注册wcf服务。为了检查它,我稍微更改了控制台应用程序代码并直接引用了WcfService1程序集而不是ServiceRefence。代码如下所示:



 使用系统; 
使用 System.Collections.Generic;
使用 System.IO;
使用 System.Linq;
使用 System.Net;
使用 System.Text;
使用 System.ServiceModel;
使用 System.ServiceModel.Channels;
使用 WcfService1; // 直接引用程序集而不是ServiceRefernce(添加引用选项)


命名空间 ConsoleClient
{
class 程序
{

静态 void Main( string [] args)
{

GenerateGetRequest();


}

private static void GenerateGetRequest()
{
// 生成获取请求
string url = HTTP://localhost/WcfServices/Service5.svc;
HttpWebRequest GETRequest =(HttpWebRequest)WebRequest.Create(url);
GETRequest.Method = GET;

Console.WriteLine( 发送GET请求);
HttpWebResponse GETResponse =(HttpWebResponse)GETRequest.GetResponse();
Stream GETResponseStream = GETResponse.GetResponseStream();
StreamReader sr = new StreamReader(GETResponseStream);

Console.WriteLine( 来自服务器的响应);
Console.WriteLine(sr.ReadToEnd());
Console.ReadLine();
}

}
}





在上面的代码中我使用的是HttpWebRequest和HttpWebResponse方法访问动态注册的Web Service。



由于我是WCF和DI(动态注入)的初学者,我被困住了。

我想我做错了什么。请建议我成功运行此方法并采取措施。



提前致谢。

解决方案

< blockquote>首先我的建议是联系原作者。



同时,您可以尝试Google建议的一些解决方案。我在下面给出一些链接。尝试那里解释的解决方案。



1. 请求的服务,'http://Service.svc'无法激活。有关详细信息,请参阅服务器的诊断跟踪日志。 [ ^ ]

2 。 WCF服务 - 无法激活 [ ^ ]




此问题已解决。实际上问题在于下载的zip文件。我再次下载它并在解压缩之前取消阻止zip文件。



谢谢。


Hi,

I am learning WCF web services and I come across this article Dynamic (runtime) Generation of a WCF Service contract, about creating service contract dynamically. I downloaded the given code and tried running it but it didn't succeed. It throws the following error:

{"The requested service, 'http://localhost/WcfService1/Service5.svc' could not be activated. See the server's diagnostic trace logs for more information."}

I think it is unable to register the wcf service dynamically. To check it I changed the console application code little bit and referenced the WcfService1 assembly directly instead of ServiceRefence. The code looks as below:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Channels;
using WcfService1; // Referenced the assembly directly instead of ServiceRefernce (Add References option)


namespace ConsoleClient
{
    class Program
    {

        static void Main(string[] args)
        {
            
                GenerateGetRequest();
               
               
        }
        
        private static void GenerateGetRequest()
        {
            //Generate get request
            string url = "http://localhost/WcfServices/Service5.svc";
            HttpWebRequest GETRequest = (HttpWebRequest)WebRequest.Create(url);
            GETRequest.Method = "GET";

            Console.WriteLine("Sending GET Request");
            HttpWebResponse GETResponse = (HttpWebResponse)GETRequest.GetResponse();
            Stream GETResponseStream = GETResponse.GetResponseStream();
            StreamReader sr = new StreamReader(GETResponseStream);

            Console.WriteLine("Response from Server");
            Console.WriteLine(sr.ReadToEnd());
            Console.ReadLine();
        }
       
    }
}



In the above code i am using HttpWebRequest and HttpWebResponse methods to access the Web Service which is registered dynamically.

As I am a beginner in WCF and DI (Dynamic Injection), I am stuck.
I suppose am doing something wrong. Please suggest me the way to run this successfully and steps to do it.

Thanks in advance.

解决方案

First my suggestion is to contact the original author about this.

At the mean time, you can try some solutions suggested by Google. I am giving some links below. Try the solutions explained there.

1. The requested service, ‘http://Service.svc’ could not be activated. See the server’s diagnostic trace logs for more information.[^]
2. WCF Service - could not be activated[^]


Hi,
This problem is solved. Actually the issue was with the downloaded zip file. I downloaded it again and unblocked the zip file before unzipping it.

Thanks.


这篇关于动态(运行时)生成WCF服务合同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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