I've created a simple WCF service inside of WebApplication project.
[ServiceContract(Namespace = "http://my.domain.com/service")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MyService
{
[OperationContract]
public string PublishProfile(out string enrollmentId, string registrationCode)
{
enrollmentId = null;
return "Not supported";
}
built - everything is compiled successfully
After that I've tried to open service in browser, I've got the following error:
Operation 'PublishProfile' in contract 'MyService' specifies an 'out' or 'ref' parameter. Operations with 'out' or 'ref' parameters are not supported
Can't I use 'out' parameters?
What is wrong here?
Thanks
P.S. I use VS2008 SP1, .NET 3.5
See Designing WCF interface: no out or ref parameters
Try this:
I believe the default body style (bare) only supports a single return value.
I think the
Out
parameter should come after.it should be like this:
Also, you are setting the string to
null
- why not usestring.Empty
?The problem in my case was that default service configuration created in my ASP.NET application with Visual Studio wizard was a service type. Endpoint binding was "webHttpBinding". As far as I understand now it is binding for REST services, and they just don't have physical ability to work with out parameters. For them out parameter is not supported. And what I actually needed was a 'basicHttpBinding" that allows to work with out parameters.
Many thanks to everybody who helped me to figure out that.
The answer I've found was:
"The idea of an out parameter is that the method will instantiate the null reference that you pass in. A web service is stateless; therefore the handle that you have on an object that goes into a webservice as a parameter will not be the same as the one that makes it into the webservice server side. The nature of this prevents out parameters."
Source