HighTechTalks DotNet Forums  

Visual Studio WebMethod with specific SOAP format

Dotnet Distributed Applications microsoft.public.dotnet.distributed_apps


Discuss Visual Studio WebMethod with specific SOAP format in the Dotnet Distributed Applications forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Ernesto García García
 
Posts: n/a

Default Visual Studio WebMethod with specific SOAP format - 02-21-2007 , 12:03 PM






Hi experts,

I need a Web Service with a specific SOAP format. Its SOAP request and
response parameters must be XML elements with no nesting, for example:

<soap:Body>
<MyMethod xmlns="http://tempuri.org/">
<input1>input1</input1>
<input2>input2</input2>
</MyMethod>
</soap:Body>

However, using Visual Studio 2005, I cannot see a way to build a Web
Service like that. I put for instance:

[WebMethod]
public Object MyMethod(Object input1, Object input2) {
Object output = new Object();
output.my_string = "Hello World";
return output;
}

public class Object
{
public string my_string;
}

But this builds a Web Service with nested elements inside the request:
<soap:Body>
<MyMethod xmlns="http://tempuri.org/">
<input1>
<my_string>string</my_string>
</input1>
<input2>
<my_string>string</my_string>
</input2>
</MyMethod>
</soap:Body>

and inside the response:

<soap:Body>
<MyMethodResponse xmlns="http://tempuri.org/">
<MyMethodResult>
<my_string>string</my_string>
</MyMethodResult>
</MyMethodResponse>
</soap:Body>


Do you know how can I get this done with Visual Studio?

Thank you in advance and regards,
Tito

Reply With Quote
  #2  
Old   
RYoung
 
Posts: n/a

Default Re: Visual Studio WebMethod with specific SOAP format - 02-27-2007 , 06:32 PM






You might have better luck if you use the XSD schema designer to design the
structure of the message that leaves the service. Then use xsd.exe to
generate the class file for that schema, which you can then use as objects
in your web service code.

For example: the MyMethod response would look like this in schema:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="XMLSchema1"
targetNamespace="http://tempuri.org/XMLSchema1.xsd"
elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema1.xsd"
xmlns:mstns="http://tempuri.org/XMLSchema1.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="MyMethodResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="input1" type="xs:string" />
<xs:element name="input2" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

All I did there was use the schema designer in Visual Studio, dragged and
dropped an element on it, added "input1" and "input2" to the element, and
left their default types as strings.

You can get as complex as you need to do with the "message" design. For
example, say MyMethod had "input1" as a part, and another part was
"Customer"

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="XMLSchema1"
targetNamespace="http://tempuri.org/XMLSchema1.xsd"
elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema1.xsd"
xmlns:mstns="http://tempuri.org/XMLSchema1.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="MyMethodResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="input1" type="xs:string" />
<xs:element name="input2" type="xs:string" />
<xs:element name="Customer" type="CustomerType" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="CustomerType">
<xs:sequence>
<xs:element name="fname" type="xs:string" />
<xs:element name="lname" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>

Again, just using the designer. This time since MyMethodResponse contains a
part named "Customer" that is of the "CustomerType", I defined the
CustomerType complexType.

Then I just copied and pasted the xml here for you to see.

Anyways, save that file as "Messages.xsd", then fire up the .NET command
prompt and run:

xsd Messages.xsd /classes

The output will be a file named Messages.cs with serializable class
definitions. Something like this:

[Serializable]
class MyMethodResponse
{
public string input1;
public string input2;
}

Then in your webservice:

[WebMethod]
public MyMethodResponse MyMethod(string x, string y)
{
MyMethodResponse response = new MyMethodResponse();
response.input1 = "hello";
response.input2 = "world";
return response;
}

I would suggest defining the request/response messages in schema. This will
prevent the use platform specific types, like Object, and will enforce that
your messages conform to standard schema defined types. You'll have more
control over the shape of the incoming messsage, and outgoing message.

Ron

"Ernesto García García" <titogarcia_nospamplease_ (AT) gmail (DOT) com> wrote in
message news:erhu1v$b3k$1 (AT) hefestos (DOT) uned.es...
Quote:
Hi experts,

I need a Web Service with a specific SOAP format. Its SOAP request and
response parameters must be XML elements with no nesting, for example:

soap:Body
MyMethod xmlns="http://tempuri.org/"
input1>input1</input1
input2>input2</input2
/MyMethod
/soap:Body

However, using Visual Studio 2005, I cannot see a way to build a Web
Service like that. I put for instance:

[WebMethod]
public Object MyMethod(Object input1, Object input2) {
Object output = new Object();
output.my_string = "Hello World";
return output;
}

public class Object
{
public string my_string;
}

But this builds a Web Service with nested elements inside the request:
soap:Body
MyMethod xmlns="http://tempuri.org/"
input1
my_string>string</my_string
/input1
input2
my_string>string</my_string
/input2
/MyMethod
/soap:Body

and inside the response:

soap:Body
MyMethodResponse xmlns="http://tempuri.org/"
MyMethodResult
my_string>string</my_string
/MyMethodResult
/MyMethodResponse
/soap:Body


Do you know how can I get this done with Visual Studio?

Thank you in advance and regards,
Tito



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.