How can I set a namespace without overwriting the service configuration name using SvcUtil.exe?
Asked Answered
V

2

5

I'm using SvcUtil.exe to generate my WCF code, like this:

SvcUtil.exe http://www.MyServer.com:8080/MyService/mex /out:"C:\test.cs" /mc

I can get it to work, but if I set add a /namespace argument(/namespace:*,MyNamespace), it overwrites the ConfigurationName value on the generated ServiceContractAttribute of the generated interface:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName="MyNamespace.MyServiceName")]
public interface MyServiceName
{ ... }

If I don't set the namespace, the value of ConfigurationName is "MyServiceName", which is correct ("MyNamespace.MyServiceName" is incorrect and does not work). I've tried adding a /ServiceName:MyService argument, but it tells me that it says

Error: The /serviceName: option conflicts with other options. Review your use of the tool.

How can I specify a namespace for my generated classes without overwriting the ConfigurationName?

Vickers answered 2/1, 2011 at 19:29 Comment(0)
F
8

I'm having the same issue. I have a ServiceReference that has ConfigurationName="MyWebService.MyWebServiceSoap" that was generated when it was added through VisualStudio.NET 2010. When I use svcutil to generate that same class from msbuild, svcutil wants to set the ConfigurationName equal to the value I set for the namespace. So if I set the /n attribute like so:

/n:*,MyApplication.MyWebService.MyWebServiceSoap

I get the proper namespace for my generated classes, but the ConfigurationName is also set to MyApplication.MyWebService.MyWebServiceSoap.

This seems to indicate that VS.NET does not use svcutil, and there are posts I found that seem to indicate this as well.

I wish I had a better answer, but since I'm using svcutil from MSBuild, my solution was to let svcutil generate the class with the incorrect ConfigurationName and then use the FileUpdate task to modify that name using a regex. Again, it's far from ideal, but I can't see anything in the svcutil documentation that lets you specify the ConfigurationName.

Also, it's worth mentioning that the serviceName option is used to export metadata from compiled code, it's not valid for generating client proxy classes, which is probably why you were getting that serviceName option conflicts error.

See: http://msdn.microsoft.com/en-us/library/aa347733.aspx

Falito answered 3/2, 2011 at 20:33 Comment(0)
U
2

Not a direct answer to the question, but the reason why the namespace change isn't working for you is that probably you forgot to update the config contract reference to that service.

In your app/web config, look for the

 <client>
    <endpoint .. contract="MyServiceName">
    </endpoint>
 </client>

Look at the contract attribute. When you didn't specify the namespace in svcutil it generated MyServiceName, and in web.config you referenced your service name with just the name of the interface. Now, your interface is inside a namespace, so you need to change the config to read:

 <client>
    <endpoint .. contract="MyNamespace.MyServiceName">
    </endpoint>
 </client>

In short, the ConfigurationName property in attribute has to match the namespace and class name in the contract attribute of your config file. It's a key by which it finds the matching configuration.

Unamuno answered 3/9, 2013 at 14:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.