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
> Hi experts,
>
[quoted text clipped - 49 lines]
> Thank you in advance and regards,
> Tito