views:

407

answers:

1

I have two websites, both using .Net framework 3.5. One website is hosting a soap web service and the other is referencing this service. I'm having some unexpected happenings with my web method signatures. I have a simple method in my web service with a signature such as:

[WebMethod]
public string[] HelloWorld()
{
    return new[] { "Hello World" };
}

But when I reference this web service using the 'Add Service Reference' feature in VS2008, with configuration set to "Always generate message contracts" (although when i check the 'reuse types in referenced assemblies', i seem to have the same issue), the signature seems to be changed by the auto generated proxy objects to the following:

HelloWorldResponse HelloWorld(HelloWorldRequest request)

I've tried to look this up on the net, but having trouble finding something that will simply explain to me why this is happening, and whether I can/should try to work around it?

I also have this question: How does one determine whether they should choose the service reference configuration option to "reuse types in referenced assemblies" and "always generated message contracts"?

+1  A: 

The message-contracts option might have this effect; the purpose here being to allow fine-grained control over the underlying request. Ultimately, what you are sending (behind the scenes) is a request payload.

The reuse-types option is more typically used with objects (not things like string[]) - and means that if you have a 100% matching Customer (say) class locally, it can re-use that for the web-service rather than generating a proxy type.

Additionally, note that you aren't actually consuming a WCF service ([WebMethod] is the older web-service style). As such you may have better results with a "Web Reference"; when adding the service, hit "Advanced", then "Add Web Reference...". This uses the older UI and wsdl.exe to generate code intended for [WebMethod] (asmx), rather than WCF (svc).

Of course, rather than hosting a [WebMethod], you could (since the server is also 3.5) host a WCF service; this may make things easier.

A final point of WCF; if you really want the same contract at client and server, you can use either assembly or class sharing to use the very same types at both end. This is not supported for [WebMethod], though.

Marc Gravell
++1 for suggesting using WCF for the service. OP: Microsoft considers ASMX to be "legacy technology". Since you're already using it for the client, you should start using it for your services.
John Saunders