views:

117

answers:

3

Is it possible to create an C# web service which returns multiple strings, without generating a complex type? (Because my client can't handle complex types and I need to return exactly 2 strings with the names: "wwretval" and "wwrettext")

I've already tried to create a struct or a class or do it with out params, but it always generated a complex type in the WSDL.

A: 

You can send the 2 string separated by a ';' . And the client split the string.

(Cowboy coder from hell)

remi bourgarel
no, i can't :( i can't change the client
manuelberger
hum ... but how do you want to send more informations if you don't change it ... can you post the client's code ?
remi bourgarel
i didn't write the client. therefore i only know how the wsdl should look like: <wsdl:message name="UploadResponse"><wsdl:part name="wwretval" type="xsd:string"/><wsdl:part name="wwrettext" type="xsd:string"/></wsdl:message>
manuelberger
A: 

Could you send them as an XML blob or, failing that, pack the strings into a single string separater by a nonprinting character such as \n then split them at the other end?

The latter is not exactly elegant but could work.

Since you can't change the client perhaps you can fool it by forcing Soap to use RPC mode with literal binding:

namespace WebTest
{
    public struct UploadResponse
    {
        public string wwretval;
        public string wwrettext;
    }

    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.None)]
    [System.ComponentModel.ToolboxItem(false)]

    public class Service1 : System.Web.Services.WebService
    {

        [SoapRpcMethod(ResponseElementName = "UploadResponse",Use=SoapBindingUse.Literal)]
        [WebMethod]
        public UploadResponse Upload()
        {
           UploadResponse ww = new UploadResponse();

            ww.wwretval = "Hello";
            ww.wwrettext = "World";
            return ww;
        }
    }
}

That will generate a response with two strings inside of an UploadResponse element. You can then generate a fake wsdl as described here: How do I include my own wsdl in my Webservice in C#

FixerMark
no, i can't :( i can't change the client
manuelberger
Since you can't change the client I have added a code snippet to my answer that will generate a response in the right format along with a link to an answer taht shows you how to fake the wsdl.
FixerMark
A: 

edit, just read your comments on the other items

What happens if you return a string array?

Joel Martinez