开发者

How do I create a Request in XML for a .NET web service?

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="MyMethodNameRespo开发者_运维技巧nse">
<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>


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)


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">

<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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜