Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法设置Web服务构造函数参数_C#_Asp.net_Web Services_Constructor_Unity Container - Fatal编程技术网

C# 无法设置Web服务构造函数参数

C# 无法设置Web服务构造函数参数,c#,asp.net,web-services,constructor,unity-container,C#,Asp.net,Web Services,Constructor,Unity Container,问题背景: 我有一个由DLL、web服务和测试项目组成的项目。目前,我只是尝试通过使用Unity设置web服务构造函数字符串参数 问题和错误: 以下显示web服务类“VersionControlFacade”的构造函数结构: private string _url; public VersionControlService() { } public VersionControlService(string url) { _url = url; } 如果我简单地传递“u

问题背景:

我有一个由DLL、web服务和测试项目组成的项目。目前,我只是尝试通过使用Unity设置web服务构造函数字符串参数

问题和错误:

以下显示web服务类“VersionControlFacade”的构造函数结构:

 private string _url;

 public VersionControlService()
 {
 }

 public VersionControlService(string url)
 {
    _url = url;
 }
如果我简单地传递“url”参数,如下面的代码所示,就可以了:

 var newVersionControlFacade = new VersionControlFacade(@"http://somelink.com");
当我尝试使用Unity IoC容器传递它时,如图所示:

 var container = new UnityContainer();
 container.RegisterType<IVersionControlFacade, ProxyHandler>();
 container.RegisterType<Proxy>();
 container.RegisterType<VersionControlService>(new InjectionConstructor(@"http://somelink.com"));
 return container.Resolve<IVersionControlFacade>();
抛出以下错误,说明web服务不包含接受字符串参数的构造函数,即使它显然包含该参数:

结果消息:

测试方法测试单元引发异常: System.InvalidOperationException:类型VersionControl.WebService.VersionControlService没有采用参数字符串的构造函数


有人能把我引向正确的方向吗?我是否需要重新添加web引用才能看到这个新的构造函数?

尝试读取web引用,也尝试调试直接调用类,至少你会看到构造器是否被看到。这是一个带有注入构造器的示例,它对我来说很好-@LawrenceThurman不确定我是否理解通过阅读网络参考你能详细说明一下吗。我直接给这个班打了电话,效果很好,它只是想通过Unity来设置它。@SergeyLitvinov谢谢你的例子。我使用过unity,正如您和我多次展示的那样,但我从未尝试过使用unity设置web服务构造函数,这就是问题所在。抱歉-重新添加web服务。