BROTES DE GERMINADOS
BROTES DE GERMINADOS

Reputation: 399

Error in Service Reference - Operation with MessageContractAttribute and Parameters of other Types

I've generated a proxy class to an 3rd party external asmx web service using svcutil.exe.

Locally on my development machine, everything works fine but when I deploy to a server I get the following error:

An error occurred communicating with the TBS service: The operation 'ProcessNotificationAsync' could not be loaded because it has a parameter or return type of type System.ServiceModel.Channels.Message or a type that has MessageContractAttribute and other parameters of different types. When using System.ServiceModel.Channels.Message or types with MessageContractAttribute, the method must not use any other types of parameters.

Now, I understand the reason for this error because, according to MSDN:

You can use the Message class as an input parameter of an operation, the return value of an operation, or both. If Message is used anywhere in an operation, the following restrictions apply: • The operation cannot have any out or ref parameters. • There cannot be more than one input parameter. If the parameter is present, it must be either Message or a message contract type. • The return type must be either void, Message, or a message contract type.

When I look in the generated code file I see:

  public System.Threading.Tasks.Task<ProcessNotificationResponse> ProcessNotificationAsync(int aNotificationID, string aComponentParam)

which seems to violate the above rules because ProcessNotificationResponse is MessageContractAttribute and the other parameters primitive types.

Why does this work on one machine and not the other? I would expect it to error on both machines.

Upvotes: 3

Views: 2003

Answers (2)

Saikat Chakraborty
Saikat Chakraborty

Reputation: 311

I faced same issue. I was calling some third party WCF service. Did lots of search. Finally found that the wcf service was built in FW 4.5 version and my asp.net website was targeting FW 3.5 version. Then checked the Service proxy class thoroughly and saw Service has exposed some Async methods which was returning System.Threading.Tasks of FW 4.5 version. Simply commented all the FW 4.5 related code. But luckily my actual calling methods did not have those. Things started working fine.

Another solution could be converting your asp.net project to FW 4.5 version. I tested this with a simple test application without commenting any lines in proxy class and it also worked fine.

Upvotes: 1

user2300846
user2300846

Reputation: 155

I was having this exact issue. Two dev computers worked, production computer gave this error. Turns out it is related to the fact that .net 4.5 supports ASYNC calls and .net 4.0 does not. The production computer was running server 2003 which .net 4.5 doesn't work on.

The solution was to downgrade the project to .net 4.0 and remove and re-add the reference. When set to .net 4.0, it does not add the Async calls. It now works on the production computer.

Had the production computer been able to run .net 4.5, installing .net 4.5 would have resolved the issu.

Upvotes: 4

Related Questions