multiple output parameters in .NET web service (without complex type)
Is it possible to c开发者_Python百科reate 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.
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#
You can send the 2 string separated by a ';' . And the client split the string.
(Cowboy coder from hell)
精彩评论