none
How to call HelloWorld service with parameters ? RRS feed

  • Question

  • Hi,

    we are trying to extend the HelloWorld sample.

    The webservice currently has one function HelloWorld, which returns back a string value.

    But, what if we modify this HelloWorld service, to accept some parameters also, as below:

    [WebMethod]

    public string HelloWorld (string parameter)

    {

    return parameter;

    }

    while making a call, we would write

    <Route>

      <Criteria>(ACTION EQ 'http://tempuri.org/HelloWorld')</Criteria>
      <Destination>HelloWorldParticipant[http://tempuri.org/HelloWorld?parameter="Hello World"]</Destination>
      </Route>

    But this does not work.

    Any idea on how to call webservice from here along with parameters?

    thanks & regards,

    anita.

     

    Monday, December 4, 2006 10:55 AM

Answers

  • Session Manifest expects   TargetParticipantname[TargetAction]  in Destination field.  Session knows the meta data of the target participant, so it it does not expect to supply parameter name in the Destination field. 

    you can invoke CreateUser  method in two ways

     

    Method 1:

    Specify following routing criteria

    <Route>                                                                                                                                                                                                            <Criteria>(ACTION EQ 'http://tempuri.org/CreateUser')</Criteria>
      <Destination>HelloWorldParticipant[http://tempuri.org/CreateUser]</Destination>
      </Route>

    Regarding how to send request. 

    Send message to session with wsa:To = SessionUri and with target participant action  (was:Action = "htp://tempuri.org/CreateUser"). Soap Body  of the message should contain the "CreateUserRequest"  object.

     

    method 2:

    <Route>                                                                                                   

    <Criteria>( MESSAGE EQ  'CreateUserRequest')</Criteria>
      <Destination>HelloWorldParticipant[http://tempuri.org/CreateUser]</Destination>
      </Route>

    Regarding how to pass parameter.  Send message to session with wsa:To = SessionUri and with target participant action  (was:Action = SessionActions.RouteMessageToParticipant) with soap body containiing CreateUserRequest. Soap Body  of the message should contain the

    "CreateUserRequest"  object.

     (  Microsoft.ConnectedServices.Contracts.Session  assembly defines  SessionActions.RouteMessageToParticipant)

     

    If you want to know how the request should be set in soap body, check wsdl of the hello word service that gives how soap body that appear in XML format.

     

    Friday, December 8, 2006 8:53 PM

All replies

  • Anita - You need to modify the client to send the message to Session with body containing

    <string>Hello Anita</string>

    and leave the routing entry as it was before.

    <Route>

      <Criteria>(ACTION EQ 'http://tempuri.org/HelloWorld')</Criteria>
      <Destination>HelloWorldParticipant[http://tempuri.org/HelloWorld]</Destination>
      </Route>

    It should work.

    Note: You cannot modify the content of the message in the routing table.

    Thanks

    Wednesday, December 6, 2006 6:04 AM
  • Hi,

    Thanks for your reply.

    Actually, there should be some way to call this HelloWorld web service, with parameters. For the moment we are considering very simple service, with just 1 input parameter. But what if there was a web service which accepted too many input parameters, and its output (return value) was actually based upon the input parameters ? In that case, how can we modify the web service itself ?

    Thanks,                                                                                                                                                          Anita.

    Wednesday, December 6, 2006 7:53 AM
  • Anita - The recommended approach is to have a Request and Response class defined for your Webmethod / SoapMethod / Operation.

    For example let us take a method CreateUser. The signature would look like

    Public CreateUserResponse CreateUser (CreateUserRequest request)
    {
       // Your logic goes here.

        return CreateUserResponse;
    }


    CreateUserRequest class may contain multiple properties. You may also want to think in this terms when you design a webservice as this gives you flexibilty to add any number of parameters in the future without breaking the existing clients

    Public class CreateUserRequest
    {
              private string userName;

     public CreateUserRequest ()
     {

     }
     
     Public string UserName;
     {
      get{
       return this.userName;

      }
      set{
       this.userName = value;
      }
     }

     Public string Password;
     //Get/SetGoes here

     Public string FirstName; 
     //Get/SetGoes here

     Public string LastName;
     //Get/SetGoes here 

    }

    Similarly you could define a class for the CreateUserResponse which could carry multiple parameters

    Also when you want to return errors make sure you return SoapFaults rather than sending custom error messages in the CreateUserResponse

     

    Thursday, December 7, 2006 7:43 PM
  • Hi,

    Thanks for your reply.

    The approach specified by you, seems to be proper when in future we need to extend the number of parameters, we dont break the function signature. But still i am not clear of as, how to call this webservice (CreateUser in above case) from the CSF framework.

    i.e. <Route>                                                                                                                                                                                                            <Criteria>(ACTION EQ 'http://tempuri.org/CreateUser')</Criteria>
      <Destination>HelloWorldParticipant[http://tempuri.org/CreateUser'?parameter="CreateUserRequest"]</Destination>
      </Route>

    above method does not work.

    so, my question is how do we pass this "CreateUserRequest" object to this function?

    Thanks,

    Anita.

    Friday, December 8, 2006 8:38 AM
  • Session Manifest expects   TargetParticipantname[TargetAction]  in Destination field.  Session knows the meta data of the target participant, so it it does not expect to supply parameter name in the Destination field. 

    you can invoke CreateUser  method in two ways

     

    Method 1:

    Specify following routing criteria

    <Route>                                                                                                                                                                                                            <Criteria>(ACTION EQ 'http://tempuri.org/CreateUser')</Criteria>
      <Destination>HelloWorldParticipant[http://tempuri.org/CreateUser]</Destination>
      </Route>

    Regarding how to send request. 

    Send message to session with wsa:To = SessionUri and with target participant action  (was:Action = "htp://tempuri.org/CreateUser"). Soap Body  of the message should contain the "CreateUserRequest"  object.

     

    method 2:

    <Route>                                                                                                   

    <Criteria>( MESSAGE EQ  'CreateUserRequest')</Criteria>
      <Destination>HelloWorldParticipant[http://tempuri.org/CreateUser]</Destination>
      </Route>

    Regarding how to pass parameter.  Send message to session with wsa:To = SessionUri and with target participant action  (was:Action = SessionActions.RouteMessageToParticipant) with soap body containiing CreateUserRequest. Soap Body  of the message should contain the

    "CreateUserRequest"  object.

     (  Microsoft.ConnectedServices.Contracts.Session  assembly defines  SessionActions.RouteMessageToParticipant)

     

    If you want to know how the request should be set in soap body, check wsdl of the hello word service that gives how soap body that appear in XML format.

     

    Friday, December 8, 2006 8:53 PM
  • I have a same problem.

    In HelloWorld sample, I changed HelloWorld() method as HelloWorld(string str) in Service.cs

    But, when I run the client,  a parameter which is entered is not delivered to webservice, str value is also null.

    message's SerializedXML is as belows.

    What's wrong? Which source code of sample client should be modified?

    ===================================================================================

    <env:Envelope xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:env="http://www.w3.org/2003/05/soap-envelope"><env:Header><wsa:Action>http://tempuri.org/HelloWorld</wsa:Action><wsa:FaultTo><wsa:Address>soap.tcp://daisy:9100/UiFormService</wsa:Address></wsa:FaultTo><wsa:From><wsa:Address>soap.tcp://daisy:9100/UiFormService</wsa:Address></wsa:From><wsa:MessageID>urn:uuid:944ccf6e-380f-47a5-9268-6ccd32a39567</wsa:MessageID><wsa:ReplyTo><wsa:Address>soap.tcp://daisy:9100/UiFormService</wsa:Address></wsa:ReplyTo><wsa:To>http://daisy/Session30/Session.ashx</wsa:To><csfse:SessionID xmlns:csfse="http://Microsoft/ConnectedServices/2006/06/Session/">urn:fa7c169b-0eaf-44e0-8c5d-d5fc3a4b5d02</csfse:SessionID></env:Header><env:Body><string xmlns="http://tempuri.org/">fasdfasfafsda</string></env:Body></env:Envelope>

    ===================================================================================

    Wednesday, January 31, 2007 2:14 AM
  • Hi,

    You can also access the request parameter information by using RequestContext. It will give you access to the Soap envelop body.

    Thanks,

    Ashish

    Wednesday, January 31, 2007 5:31 AM
  • I've got it.

    When web service is defined as

    public string HelloWorld(string str)

    Soap message must be not

     

    <env:Body><string xmlns="http://tempuri.org/">fasdfasd</string>
    </env:Body>

    but

    <env:Body><HelloWorld xmlns="http://tempuri.org/">
          <str>string</str>
        </HelloWorld>
    </env:Body>

     

    SetBodyObject(string type) makes this problem, and I think, I really need SetBodyObject(HelloWorld type).

    But I can't find HelloWorld object even though I referrenced web service. How can I find HelloWorld object?

     

    Wednesday, January 31, 2007 8:43 AM
  • Hi senthil/All,

       If you have a sample application for hello world service with parameters, please send to the following mail id. Its very urgent. I tried so many times even i went through the interception example also. But, i am not able to understand that example. I have to do some POCs in CSF. Please do the needful.

    prajasekaran@dotnetsekar.com

    Regards,

    Rajasekaran

    Thursday, February 22, 2007 9:20 AM