IDispatchMessageInspector.AfterReceiveRequest - bypass service call and return manually response

Hi,
I am using a service behavior class that implements IDispatchMessageInspector.AfterReceiveRequest to handle Health Check Service request that require skipping the actual operation's code and instead manually crafting a response message from "BeforeSendReply".
I want to skip any processing on the request and instead want to return manual response from "BeforeSendReply".
It has been pointed out in various forum threads that setting ref request parameter to null will skip the normal message processing and transition directly to BeforeSendReply. I have tracing enabled on my service and observe that underneath it still tries to
deserialize the message and throws an exception:
NullReferenceException: Object reference not set to an instance of an object.
System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc)
System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
any idea how can I skip the service call and instead return a manual response back?
   

This is not correct (setting request to null to bypass the service), unfortunately WCF doesn't have any out-of-the-box way of doing that.
You can, however, use a few more of the extensibility points in WCF to make this scenario work. You'll need at least an IDispatchMessageFormatter (to prevent the message from being read / deserialized since it's not necessary) and an IOperationInvoker (to
actually bypass invoking the service method). You can use the operation context to pass information between those extensibility points.
You can find more information about those three interfaces in my ongoing blog series about WCF extensibility points:
IDispatchMessageInspector: http://blogs.msdn.com/b/carlosfigueira/archive/2011/04/19/wcf-extensibility-message-inspectors.aspx
IDispatchMessageFormatter: http://blogs.msdn.com/b/carlosfigueira/archive/2011/05/03/wcf-extensibility-message-formatters.aspx
IOperationInvoker: http://blogs.msdn.com/b/carlosfigueira/archive/2011/05/17/wcf-extensibility-ioperationinvoker.aspx
The code which uses those extensions to skip the operation based on a decision made in the message inspector:
public class Post_55ef7692_25dc_4ece_9dde_9981c417c94a
[ServiceContract(Name = "ITest", Namespace = "http://tempuri.org/")]
public interface ITest
[OperationContract]
string Echo(string text);
public class Service : ITest
public string Echo(string text)
return text;
static Binding GetBinding()
BasicHttpBinding result = new BasicHttpBinding();
return result;
public class MyOperationBypasser : IEndpointBehavior, IOperationBehavior
internal const string SkipServerMessageProperty = "SkipServer";
public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
endpointDispatcher.DispatchRuntime.MessageInspectors.Add(new MyInspector(endpoint));
public void Validate(ServiceEndpoint endpoint)
public void AddBindingParameters(OperationDescription operationDescription, BindingParameterCollection bindingParameters)
public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
dispatchOperation.Formatter = new MyFormatter(dispatchOperation.Formatter);
dispatchOperation.Invoker = new MyInvoker(dispatchOperation.Invoker);
public void Validate(OperationDescription operationDescription)
class MyInspector : IDispatchMessageInspector
ServiceEndpoint endpoint;
public MyInspector(ServiceEndpoint endpoint)
this.endpoint = endpoint;
public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
Message result = null;
HttpRequestMessageProperty reqProp = null;
if (request.Properties.ContainsKey(HttpRequestMessageProperty.Name))
reqProp = request.Properties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
if (reqProp != null)
string bypassServer = reqProp.Headers["X-BypassServer"];
if (!string.IsNullOrEmpty(bypassServer))
result = Message.CreateMessage(request.Version, this.FindReplyAction(request.Headers.Action), new OverrideBodyWriter(bypassServer));
return result;
public void BeforeSendReply(ref Message reply, object correlationState)
Message newResult = correlationState as Message;
if (newResult != null)
reply = newResult;
private string FindReplyAction(string requestAction)
foreach (var operation in this.endpoint.Contract.Operations)
if (operation.Messages[0].Action == requestAction)
return operation.Messages[1].Action;
return null;
class OverrideBodyWriter : BodyWriter
string bypassServerHeader;
public OverrideBodyWriter(string bypassServerHeader)
: base(true)
this.bypassServerHeader = bypassServerHeader;
protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
writer.WriteStartElement("EchoResponse", "http://tempuri.org/");
writer.WriteStartElement("EchoResult");
writer.WriteString(this.bypassServerHeader);
writer.WriteEndElement();
writer.WriteEndElement();
class MyFormatter : IDispatchMessageFormatter
IDispatchMessageFormatter originalFormatter;
public MyFormatter(IDispatchMessageFormatter originalFormatter)
this.originalFormatter = originalFormatter;
public void DeserializeRequest(Message message, object[] parameters)
if (message.Properties.ContainsKey(MyOperationBypasser.SkipServerMessageProperty))
Message returnMessage = message.Properties[MyOperationBypasser.SkipServerMessageProperty] as Message;
OperationContext.Current.IncomingMessageProperties.Add(MyOperationBypasser.SkipServerMessageProperty, returnMessage);
OperationContext.Current.OutgoingMessageProperties.Add(MyOperationBypasser.SkipServerMessageProperty, returnMessage);
else
this.originalFormatter.DeserializeRequest(message, parameters);
public Message SerializeReply(MessageVersion messageVersion, object[] parameters, object result)
if (OperationContext.Current.OutgoingMessageProperties.ContainsKey(MyOperationBypasser.SkipServerMessageProperty))
return null;
else
return this.originalFormatter.SerializeReply(messageVersion, parameters, result);
class MyInvoker : IOperationInvoker
IOperationInvoker originalInvoker;
public MyInvoker(IOperationInvoker originalInvoker)
if (!originalInvoker.IsSynchronous)
throw new NotSupportedException("This implementation only supports synchronous invokers");
this.originalInvoker = originalInvoker;
public object[] AllocateInputs()
return this.originalInvoker.AllocateInputs();
public object Invoke(object instance, object[] inputs, out object[] outputs)
if (OperationContext.Current.IncomingMessageProperties.ContainsKey(MyOperationBypasser.SkipServerMessageProperty))
outputs = null;
return null; // message is stored in the context
else
return this.originalInvoker.Invoke(instance, inputs, out outputs);
public IAsyncResult InvokeBegin(object instance, object[] inputs, AsyncCallback callback, object state)
throw new NotSupportedException();
public object InvokeEnd(object instance, out object[] outputs, IAsyncResult result)
throw new NotSupportedException();
public bool IsSynchronous
get { return true; }
public static void Test()
string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
ServiceHost host = new ServiceHost(typeof(Service), new Uri(baseAddress));
ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(ITest), GetBinding(), "");
endpoint.Behaviors.Add(new MyOperationBypasser());
foreach (var operation in endpoint.Contract.Operations)
operation.Behaviors.Add(new MyOperationBypasser());
host.Open();
Console.WriteLine("Host opened");
ChannelFactory<ITest> factory = new ChannelFactory<ITest>(GetBinding(), new EndpointAddress(baseAddress));
ITest proxy = factory.CreateChannel();
Console.WriteLine(proxy.Echo("Hello"));
Console.WriteLine("And now with the bypass header");
using (new OperationContextScope((IContextChannel)proxy))
HttpRequestMessageProperty httpRequestProp = new HttpRequestMessageProperty();
httpRequestProp.Headers.Add("X-BypassServer", "This message will not reach the service operation");
OperationContext.Current.OutgoingMessageProperties.Add(
HttpRequestMessageProperty.Name,
httpRequestProp);
Console.WriteLine(proxy.Echo("Hello"));
((IClientChannel)proxy).Close();
factory.Close();
Console.Write("Press ENTER to close the host");
Console.ReadLine();
host.Close();

Similar Messages

  • Join a service call and one serial number?

    In admin web tools
    Can  join a service call and one customer equipment card (serial number) ?

    The company sells machines for industry.
    Every machine and component has a serial number and u201Ccustomer equipment cardu201D in SBO.
    Usually, If the customer has a problem call to company.
    1.-  SBO user get the u201Ccall serveru201D
    2.- SBO user support join the u201Ccall serveru201D and  u201Ccustomer equipment cardu201D
    3.- SBO user go to call server  create a Delivery (works and equipment)
    Unfortunately the technical support, works in customer company and usually canu2019t entry to SBO in several days.
    We like use the u201Cweb toolsu201D, the technical support uses the web and can see the u201Ccall serveru201D, the Customer and marketing documents.
    But canu2019t assign a u201Ccustomer equipment cardu201D to  u201Ccall serveru201D and synchronize to SAP and create a Delivery by WEB
    Can you proposal a new work flow by web?
    Muchas gracias.

  • Link between Service Call and Marketing documents not working

    Hello all,
    I found a field in Marketing Documents - Rows data - that should be the link between a Service Call and the Marketing Documents.
    The field is for example "INV1.isSrvCall" but, even if I create an Invoice from the Service Call, the field will be populated with the value "N".
    Dows anyone knows how to make this field work? Or any workarround to make the connection between a Service Call and the generated documents?
    Thanks in advance,
    Kind Regards

    The problem with SCL4  is that SAP updates it way too late in the process to be meaningful while in the module. You create a service order, then go into the expense document. That is when we need to know the service call id and the internalsn of the equipment being worked on Only when you get out of the service module do SAP post to SCL4.  
    The data (before writing to SCL$) exists as a veriable on the original service form.  But can we access it from the expense document?
    The question is how to access the data (service id) on the original service form from an expense document within the servide module. It is the service form, and that is currently not in focus, so I do not know if you can access it as a varaible, while in the expense document (sales order or invoice) that is in focus.
    Can any one help with this/
    David

  • Call and Return

    Hi, hope someone can help.....
    I have constructed an authorware piece that contains severel
    pages(Map icons) sitting on a framework icon.
    I currently have a display icon showing a Page xx of xx Pages
    display on each page. As there is 28 pages this means I have 28 of
    these Icons.
    I have tried to replace these 28 Icons with a single routine
    that is called from each page.
    I have added a new framework icon and called it extras, I
    then use a map Icon called PageStart, inserted several calculation
    and display icons as neccessary. I then use a Navigation Icon set
    to Call and Return to call the PageStart sub-routine. In the
    PageStart map Icon the last Icon is a Navigation Icon set to nearby
    - Exit Framework/Return.
    This does work a treat, however after the sub-routine is
    executed and the jump is made back to the original flowline
    everything contained in the sub-routine is wiped off the face of
    the planet. Just as if I had used an erase Icon.
    Am I doing this right????
    Is there a way to do this????

    "The Pc Doctor" <[email protected]> wrote in
    message
    news:[email protected]...
    > Thanks to you both for your replies...
    >
    >
    First to Mike
    >
    > Pity about the frameworks - I am using several icons to
    calculate the
    > section
    > and page numbers from the positioning of a caluclation
    icon for example
    > Round(SubStr(IconTitle(IconParent(IconID)),2,3)) this
    gives me the page
    > number
    > based on the 2nd and 3rd character of the page title -
    101 How to use this
    > package. I then have a graphical display of which
    sections and pages have
    > been
    > completed - we are talking about a Calc Icon,and a
    couple of Display icons
    >
    > The reason I use this is so that I can drop three icons
    into the flowline
    > of
    > any page at the beginning and dont have to worry about
    changing
    > currentpage or
    > current section numbers. I don't even have to add or
    minus 1 from a
    > variable
    > to display the page number. If I get rid of a page all I
    need to do is to
    > change the page title and everything else is taken care
    of automatically.
    >
    > This is probably all my fault as I'm so used to VB where
    you would put
    > this in
    > a Sub Routine then just call it at the beginning of each
    page. It is no
    > problem just pasting three or four icons into the start
    of each page, I'm
    > just
    > looking for a tidy way to do it.
    >
    > For info I've even tried having the 'StartPage' map icon
    on the main
    > flowline
    > and not in a framework icon. I had to use the GoTo
    command to call then
    > return
    > from the map icon but guess what - that didn't work
    either.
    >
    >
    Next to Amy,
    >
    >
    > Have tried this amy but all I ever get is Page 0 of 20
    Sounds like you forgot to set update displayed variables to
    true on the
    icon.
    > I have even tried using CurentPageNum@"Section1paging" -
    the name of my
    > framework icon, still no joy.
    >
    > Unfortunately to use my code the icon has to be part of
    the actual page
    > itself.
    >
    > Page {Round(SubStr(IconTitle(IconParent(IconID)),2,3))}
    of
    > {Round(ListCount(pagingIconIDs[sectionCurrent]))}
    >
    >
    >
    Again many thanks to you both but it looks as if I will just
    have to
    > settle
    > for having to paste in several repeated icons into each
    page flowline
    We all like doing it the hard way when we're newbies :-). At
    this point in
    Authorware's history, there's probably no point in worrying
    about trying to
    outgrow that phase.

  • ColdFusion Remote Service Calls and Dates

    Hi all, I'm hoping someone can help me out with my confusion.  I’m sending an object including datetime data from ColdFusion to a Flash application.  The datetime in the ColdFusion object include milliseconds, however, if I use the getTime() function on the Date object in the Flex application, the milliseconds have been zeroed out.  Is there any way to retain the milliseconds when the data is passed through the flexgateway?
    Thanks,
    Christine

    Hi Balaji,
    I have attached a demo of my proxy webservice called pxTest.cfc.  pxTest.cfc contains two functions, testDate and pushBackTestDate.  I also attached a simple Flex App called testDate.mxml.  And a Test file called test.cfm.
    Save pxTest.cfc to your CFC folder.  Create a new project called TestDate.  Go to the data/services tab, click "Connect to Data/Service" and select Data Service ColdFusion.  Browse to PxTest.cfc and select it for the CFC location.  Click Next, then click Finish.  Configure ReturnType as Date for both pushBackTestDate and testDate.  Paste the code from TestDate.mxml into the blank TestDate.mxml file that was created when you created the project TestDate.  Run the TestDate.mxml application.
    On load of the application a date was requested and received from pxTest.cfc.  Click Confirm Test Date and note the date returned, and the milliseconds value for that date.  Next click Push User Data back, this will call the method pushBackTestDate sending the date from the Flex app back into CF.  All pushBackTestDate does is set the value returned into session and return it back to the Flex app again.
    Click the button Show Pushed Data Result to see the date that was returned.  In my tests this date no longer has a value for milliseconds.  As long as pxTest.cfc and test.cfm run in the same session you will be able to see the dates sent and returned by running test.cfm.  The dump of that session variable and time formatted versions of that variables are displayed below:
    RETURNED
    {ts '2009-09-17 12:57:50'}
    SEND
    {ts '2009-09-17 12:57:50'}
    TimeFormat Send 12:57:50 13
    TimeFormat Returned 12:57:50 0
    Note the date sent contains milliseconds, the date returned does not have milliseconds.  Hopefully this demo will work for you and demonstrate the issue.  Please let me know if you need more information.
    Thanks,
    Christine

  • Will Service call out return an exception with an object embedded in it

    Hi,
    I have a service callout in a request pipeline.Service will throw an exception with a custom object embedded inside the exception.When i see the response $fault in the service error handler, i dont see the object.Is this something which can be done or not?if yes then guide me through it.

    Hi,
    If you invoke the service call out, and it returns a soap fault (make sure that it returns http 500), so you should be able to access the custom fault element inside $fault/con:details/con1:ReceivedFaultDetail/con1:detail
    Are you sure that your webservice is returning the fault properly?
    Are you not raising a new error after getting the response in the error handler, right?
    Regards,
    Fabio Douek.

  • Why Service Call and why not call Function module Directly in WD ABAP

    Hi,
    I have created a Webdynpro applications and the logic requires calling avrious Function modules.
    Do I need to create Service Call for each Function module or call them directly.
    It would be great if you can suggest me under what cases I need to opt for Service call
    For example, if I use 'RP_CALC_DATE_IN_INTERVAL', do I need to use Service call or call function module directly.
    Note: I have searched forums but could not get the correct answer which I want
    Thanks!

    The Service Call is really meant to be a wizard/time saver.  It has the advantage that it can generate matching context nodes/attributes for the interface of the Function Module you are calling. However everything that the service call does can also be created by hand.
    Personally I'm not a fan of what the service call wizard generates.  Its good as a time saver or for beginners, but I find I prefer to touch up the code it generates anyway. I much prefer to create a nice reusable model class with its own unit test and then consume this model class (with the service call wizard) from WD.  This model class might contain one or more function module calls depending upon what logic I need to access.

  • How to get products in E-Service Complaints and Returns ?

    Hi Gurus,
    We have a Complaints and Returns application in which we want to implement the product search functionality similar to the search we have in B2B application using TREX. If anyone already implemented or having any idea of how to implement this by using the TREX engine  ..... please help me .
    Thank you a lot in Advance!!
    Lakshman
    Edited by: lakshman reddy G on Jan 18, 2011 12:05 PM

    Hi,
    if you using the SAP standard libaries, which contains the T-Rex and catalog implementation, it should work.
    However you have to manually initizale the catalog and the connection during the application start.
    Best regards,
    Nils

  • Service call and code wizard

    Dear All,
    I am working on ECC 6.0 with Eph2 and SAP_HR SP27, when i tried to create a service call to function module in the Adapt Context i am not able to view the check box for selection.
    Also when i click the Webdynpro Code Wizard it shows only a template gallery with standard screen,from and table only, which is not not displayin the Web dynpro statement structure
    What could be the possible reason?
    Patch level update or Service activation ?
    Could you help me out in the solving this issue?

    > when i tried to create a service call to function module in the Adapt Context i am not able to view the check box for selection.
    What checkbox can you not see?  I am looking at that step in the Wizard and there isn't any checkbox - just a table control with the node type, name, object type, new name.
    >Also when i click the Webdynpro Code Wizard it shows only a template gallery with standard screen,from and table only, which is not not displayin the Web dynpro statement structure
    The Web Dynpro Code Wizard from the View-layout tab should only have the Screen, Form, and Table option.  What else where you expecting. If you want the code generation wizard then you are in the wrong place.  Form the method editor choose the Web Dynpro Code Wizard and you will get a completely different set of options than choosing the same option from the view-layout tab.

  • Script example trigger web service call and populate request from adobe

    Hello,
    I'm trying to make a adobe interactive form that needs to be populated by a web service. I have one field : In the dataconnection that is the input for the web service request and this is bound to the request. I have a button that is connected to my web service. After filling in a new value and pushing the button I want the web service request to be triggered.
    Thus anyone has a coding example or more information about using web services directly from within a Adobe Interactive form ?
    thnx, Jasper

    Hi Jasper,
    You may refer the Adobe ddevelopment center for the docs related to the execute property of the button to trigger a web service.
    <i>Alternatively, if you do not want to create a button to execute a call to a Web Service, you can do it via Script.
    Assuming your Data Connection is named ‘LeasePayment’
    For JavaScript:
    xfa.connectionSet.LeasePayment.execute(0);
    For Form Calc:
    $connectionSet.LeasePayment.execute(0);
    execute(0) indicates no data merging
    execute(1) indicates all the data in the data DOM will be remerged.</i> - Adobe doc.
    hope this will help.
    Thanks andRegards,
    Anto.

  • Service Call and Invoice For That Service Call

    What field relates an invoice created within the service call form under expenses, to the originating service call number. I know it is somewhere but I cannot find it.  The invoice needs to know the originating service calll number.
    Thanks, David

    Yes the field is there SCL4 but the problem is timing. It is posted too late to be meaningful.
    While in an invoice,  I need to capture the service call ID so that I can assign the service call id to a field in the invoice, and also
    import the remarks from the service call to the remarks on the invoice.
    The way B1 words is that SCL4 gets populated way too late in the game. The SCL4 table gets populated only after Updating  the service call itself. This is after the user has created and exited the invoice.
    Any other suggestions for dynamically capturnig the invoice id during invoice creation under a service call?
    Thanks, David

  • Posting to SCL4 -- Link an service call and an invoice --

    Is there any way to post to SCL4 sooner to create the link between a service order and an expense document.
    Currently the link is created after one leaves the service module.  That is too late to be functional. 
    Therefore you cannot grab the service id of the current service order and assign it to the marketing document created while in the service module.
    SCL4 creates a strong link between the serivce order and the expense document, it is just too late.
    The link is made on exit of the service call.  
    It would be great if the link was created when the user "Adds" the expense document (sales order or invoice) to B1 while in the service module.
    Thanks, David

    Yes the field is there SCL4 but the problem is timing. It is posted too late to be meaningful.
    While in an invoice,  I need to capture the service call ID so that I can assign the service call id to a field in the invoice, and also
    import the remarks from the service call to the remarks on the invoice.
    The way B1 words is that SCL4 gets populated way too late in the game. The SCL4 table gets populated only after Updating  the service call itself. This is after the user has created and exited the invoice.
    Any other suggestions for dynamically capturnig the invoice id during invoice creation under a service call?
    Thanks, David

  • Web service call and page fowarding

    I just started with HTML DB. I have a customer that requires the use of HTML DB for there standard look and feel, since they are using it for other applications.
    I need to use HTML DB to create a front end that is backed by either EJBs or Web services that front the EBJs, to create a single application. I can not go directly to the DB since there is to much business logic contained in the EJBs that I would be circumventing. I dont think this is a good use of tech. from either side (J2EE or HTML DB) but I did not make the decision.
    I have not seen integration with EJBs addressed (if you know of any please speak up), so I was happy to see that web services are supported.
    So....
    I have been able to call a webservice and get a result. I need to be able to format the result and create buttons based on the results returned by the web services. These buttons will call other pages that may or may not call additional webservices. In addition, I need to pass values in the web services response to pages called by the buttons generated. Any and all help would be appreciated.
    Also does the syntax for #somethine# and &someone get evaluated if used in the XSL that renders the webservice response?

    Please disregard my "additional information" post to this
    item. I posted it here by mistake!

  • How to know that a method has been called and returning value of a method

    Hi, everyone! I have two questions. One is about making judgment about whether a method has been called or not; another one is about how to return "String value+newline character+String value" with a return statement.
    Here are the two original problems that I tried to solve.
    Write a class definition of a class named 'Value' with the following:
    a boolean instance variable named 'modified', initialized to false
    an integer instance variable named 'val'
    a constructor accepting a single paramter whose value is assigned to the instance variable 'val'
    a method 'getVal' that returns the current value of the instance variable 'val'
    a method 'setVal' that accepts a single parameter, assigns its value to 'val', and sets the 'modified' instance variable to true, and
    a boolean method, 'wasModified' that returns true if setVal was ever called.
    And I wrote my code this way:
    public class Value
    boolean modified=false;
    int val;
    public Value(int x)
    {val=x;}
      public int getVal()
      {return val;}
       public void setVal(int y)
        val = y;
        modified = true;
         public boolean wasModified()
          if(val==y&&modified==true)
          return true;
    }I tried to let the "wasModified" method know that the "setVal" has been called by writing:
    if(val==y&&modified==true)
    or
    if(x.setVal(y))
    I supposed that only when the "setVal" is called, the "modified" variable will be true(it's false by default) and val=y, don't either of this two conditions can prove that the method "setVal" has been called?
    I also have some questions about the feedback I got
    class Value is public, should be declared in a file named Value.java
    public class Value
    cannot find symbol
    symbol  : variable y
    location: class Value
    if(val==y&&modified==true)
    *^*
    *2 errors*
    I gave the class a name Value, doesn't that mean the class has been declared in a file named Value.java*?
    I have declared the variable y, why the compiler cann't find it? is it because y has been out of scale?
    The other problem is:
    Write a class named  Book containing:
    Two instance variables named  title and  author of type String.
    A constructor that accepts two String parameters. The value of the first is used to initialize the value of  title and the value of the second is used to initialize  author .
    A method named  toString that accepts no parameters.  toString returns a String consisting of the value of  title , followed by a newline character, followed by the value of  author .
    And this is my response:
    public class Book
    String title;
    String author;
      public Book(String x, String y)
       { title=x; author=y; }
       public String toString()
       {return title;
        return author;
    }I want to know that is it ok to have two return statements in a single method? Because when I add the return author; to the method toString, the compiler returns a complain which says it's an unreachable statement.
    Thank you very much!

    Lets take this slow and easy. First of all, you need to learn how to format your code for readability. Read and take to heart
    {color:0000ff}http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html{color}
    Now as to your first exercise, most of it is OK but not this:   public boolean wasModified()
          if (val == y && modified == true)
                return true;
    y being a parmeter to the setValue method exists only within the scope of that method. And why would you want to test that anyways? If modified evaluates to true, that's all you need to know that the value has been modified. So you could have   public boolean wasModified()
          if (modified == true)
                return true;
       }But even that is unnecessarily verbose, as the if condition evaluates to true, and the same is returned. So in the final analysis, all you need is   public boolean wasModified()
          return modified;
       }And a public class has to be declared in a file named for the class, yes.
    As for your second assignment, NO you cannot "return" two variables fom a method. return means just that: when the return statement is encountered, control returns to the calling routine. That's why the compiler is complaining that the statement following the (first) return statement is unreachable.
    Do you know how to string Strings together? (it's called concatenation.) And how to represent a newline in a String literal?
    db

  • Calling and returning to different Vi windows

    Quick question. I want to write a project that has a main window with various buttons and when a button it clicked on i want the vi to call a different window on screen while simultaneously closing the main window. Once i'm finished with the second window and i close it i want the main window to automatically pop back up. how do i go about doing this.
    I also would like the button i previously selected in the main window to now maybe change colour to show that it has been modified and i need some of the changes that were made in the secondary window available in the Main vi.
    Hope i explained this clearly

    You're in luck, I just did this the other day. Here's how I did it. ATP Main is the sub VI I'm calling. Put this into your main VI to close it while you pop up the sub VI. Set the sub VI to show the front panel when called (set its appearance to top level VI). The main VI will hide while the sub VI runs, then when you close the sub VI, the main VI will reappear.
    Edit: forgot to show the reference to the main VI (This VI) connected to those property nodes.
    Message Edited by Marc A on 02-16-2007 08:55 AM
    Message Edited by Marc A on 02-16-2007 08:57 AM
    Attachments:
    Prod_Main.png ‏3 KB

Maybe you are looking for

  • IF NEW VARIABLE IN SQL QUERY, DISPLAYS AS LAST COLUMN + rpad not working

    Hello everybody and thank you in advance, 1) if I add a new variable to my sql query to select a column which was already in the table, it shows it in the report table as the Last column to the right. That is, if I add "street" to something like city

  • Bookmarks save only in 'recently bookmarked' folder & can not be moved to other folders

    I can no longer save bookmarks to a designated folder - they go only to 'recently bookmarked' folder and can not to moved to other folders- when attempting to move them to another folder, they appear in the designated folder list but when I return to

  • Java.lang.OutOfMemoryError: unable to create new native thread

    Hi All, I have installed weblogic server 8 sp4 in production environment . I am facing problems with JVM issues . JVM is crashing very frequently with the following errro : ####<Jun 18, 2009 10:58:22 AM IST> <Info> <Common> <IMM90K-21> <SalesCom> <Ex

  • Pass 2 different  parameters from 2 different methods to 1 method

    Hi all, To the method "renameFile" my parameter is "File dst" and to the method "renameCode" my parameter is "String name". But I need to get both the parameters "File dst" and "String name" into a single method. Could anyone please help me with this

  • Dvmatte Question

    Hello: I couldn't get the motion forum to come up this morning, but I'll give this a try anyway... I'm attempting to do some greenscreen keying and someone suggested I get dvmatte for better keying than what motion offers. WIth motion's greenscreen f