views:

48

answers:

2

How can I specify the Request object formatting in XML? My web services look like this:

[WebMethod]
public string MethodName(string str, string str2)
{
    if (random())
        return "123";
    else
        return "no";
}

Everything is in strings. How do I specify to a consumer what to request in XML? I am used to specifying this as HTTP GET:

http://domain.tld/service.asmx/MethodName?str=textgoeshere&str2=moretext

What does the whole XML Request object look like, and where can I find this format/specification in the future if I change data types or parameter names?

Edit

Current WSDL output:

<wsdl:definitions targetNamespace="my namespace">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="my namespace">
<s:element name="MyMethodName">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="str" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="str2" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="MyMethodNameResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="MyMethodNameResult" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>

Is the following an accurate XML specification?

<?xml version="1.0">
<str>1</str>
<str2>123456789</str2>
A: 

It looks like you're exposing this via SOAP, in which case the service will also expose a WSDL (Web-service description language) based schema that describes the available methods, their parameters, and their return type and constraints.

The WSDL is basically the interface definition for the service, so if method signatures are changed then clients will need to be updated accordingly. In the case of Visual Studio, you can do this by right-clicking service references and saying "Update", which will regenerate the client-side proxies to the web-service.


To help clarify: SOAP is an XML-based standard, so all SOAP messages are XML, but not all XML is SOAP. To speak to a web-service the XML you send needs to comply to the SOAP spec--so a sample message might look like (this is a tweaked sample from Wikipedia, not intended to be precisely correct for your example):

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"&gt;

<soap:Body xmlns:m="my namespace/Service">
  <m:MyMethodName>
    <m:str>someValue</m:str>
    <m:str2>otherValue</m:str2>
  </m:MyMethodName>
</soap:Body>

</soap:Envelope>
STW
Please see my edit. Thanks
David
That's very helpful--is there any way to speak to a web service strictly in XML since it is lighter weight? My application should be heavily requested.
David
Not that I'm aware of with SOAP/WSDL/UDDI. However, JSON can be used which is quite a bit lighter and simpler than even basic XML
STW
I don't need SOAP/WSDL/UDDI if that matters. I will be specifying the payload to the consumer(s), and writing the services in C# .NET. Is that possible?
David
A: 

With SOAP .Net actually generates documentation for you explaining what the XML should look like. and will even generate a form for you to test with if you are on the same box as the server.

Just go to http://domain.tld/service.asmx

(no ?wsdl, no /method etc...just the plain url)

ryber
It doesn't show me strictly XML, only SOAP 1.1, SOAP 1.2 and HTTP POST. Is there any way to specify my XML request payload like the bottom of my Edit above?
David
I'm not sure what you mean, It does show the XML. Soap IS xml, If you were to pass what it shows directly over a HTTP post with the method in the URL it would work just fine.
ryber
Sorry, I would like to pass *less* XML that the full SOAP specification. I'm looking for something similar to what I edited at the bottom of my OP.
David
ryber
strings are complex types?
David
<s:complexType>
ryber