asp.net - Want String in XML body no other strings -


i have function can return me xml tag want hustget string passed not other tag in body can edit function.

 [servicebehavior]     public class helloservice : ihelloservice     {         public string greet(string name)         {             return "hello ," + name;         }     }  public class consolemessageinspector : iclientmessageinspector, idispatchmessageinspector     {  public message createmessage(message message)         {              messagebuffer buffer = message.createbufferedcopy(int32.maxvalue);             var messagecopy = buffer.createmessage();             console.writeline(messagecopy.tostring());             return buffer.createmessage();          } } 

xml want string in body no other tag possible..

{<s:envelope xmlns:s="schemas.xmlsoap.org/soap/envelope/">; <s:header>    <action s:mustunderstand="1" xmlns="schemas.microsoft.com/ws/2005/05/addressing/none">http:/…;     </s:header> <s:body>     <greetresponse xmlns="tempuri.org/">; <greetresult>hello ,wasif</greetresult>     </greetresponse> </s:body> </s:envelope>}  

i'm guessing you're talking data goes: message header or message body that's being exchanged between client , wcf server.

to that, can either use data contract or message contract. these are, name suggests, contracts between client , host (so need them on both sides) information exchanged within particular data structure embedded in message.

so on host, you'd declare public interface, inside you'd declare data contract data members you'd give names. this:

public interface ihostinterface { [operationcontract()] messagestructure hostconnect(messagestructure inmsg); }  [datacontract()] public class messagestructure { private string headerstring = null; private string bodystring = null; [datamember(name = "textsection", order = 0)] public string text {     { return headerstring ; }     set { headerstring = value; } }  [datamember(name = "bodysection", order = 1)] public string bodystring {     { return bodystring ; }     set { bodystring = value; } } //constructors  public messagestructure(string headervalue, string bodyvalue) {     if (!string.isnullorempty(headervalue))         headerstring = headervalue;     if ((!string.isnullorempty(bodyvalue))         bodystring = bodyvalue; } } 

then when want send request client, or response host, you'd use this:

public class hostinterface: ihostinterface {     public messagestructure hostconnect (messagestructure instruct)     {      string requestheadertext = instruct.text;     string requestbodystring = instruct.bodystring;      string responseheadertext ="cat";     string responsebodytext ="dog";      messagestructure outstructure = new messagestructure(responseheadertext,responsebodytext);     return outstructure; 

here's link msdn explanation of data contracts

http://msdn.microsoft.com/en-us/library/ms733127.aspx


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -