Cannot set Web Service constructor parameter

你说的曾经没有我的故事 提交于 2019-12-11 13:47:15

问题


Question Back ground:

I have a project consisting of a DLL, a web service and a test project. Currently I'm simply trying to set the web service constructor string parameter through the use of Unity.

The issue & error:

The following shows the constructor structure of the web service class 'VersionControlFacade':

 private string _url;

 public VersionControlService()
 {
 }

 public VersionControlService(string url)
 {
    _url = url;
 }

If I simply pass the 'url' parameter as shown in the following code it is fine:

 var newVersionControlFacade = new VersionControlFacade(@"http://somelink.com");

When I try and pass it using my Unity IoC container as shown:

 var container = new UnityContainer();
 container.RegisterType<IVersionControlFacade, ProxyHandler>();
 container.RegisterType<Proxy>();
 container.RegisterType<VersionControlService>(new InjectionConstructor(@"http://somelink.com"));
 return container.Resolve<IVersionControlFacade>();

The following error is being throw stating that the web service does not contain a constructor that takes a string parameter even though it clearly does.:

Result Message:

Test method Test_Unity threw exception: System.InvalidOperationException: The type VersionControl.WebService.VersionControlService does not have a constructor that takes the parameters (String).

Can anyone steer me in the right direction here? Do I need to re-add the web reference for it to see this new constructor?

来源:https://stackoverflow.com/questions/21675845/cannot-set-web-service-constructor-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!