none
Create a request object.(Consum wcf) RRS feed

  • Question

  • I am not strong on WCF service. There is a WCF Service which locates at our server http://wsvc01/abcd/abcd.svc, now I want to write a request object code for that.

    In side the service, there is a file abcd.cs

    [ServiceContract]
        public interface iabcd
        {
            [OperationContract]
            PostPhoneCallResponse PostPhoneCall(PostPhoneCallRequest objCDRRequest);
    
            [OperationContract]
            List<PostPhoneCallResponse> LoadUnbillsFromOrion(int DBNumber);
        }
    
        public class PostPhoneCallRequest
        {
            /// <summary>
            /// Security token required to use the method
            /// </summary>
            [DataMember]
            public string Token = null;
    		//
    	}....
    	
    	[DataContract]
        public class PostPhoneCallResponse
        {
            [DataMember]
            public double ActualCallCharge = -1.0;
    		// blah
        }
    	
    	[DataContract]
        public class Message
        {
            [DataMember]
            public string MessageDesc = null;
    
            public Message(string iMessage)
            {
                MessageDesc = iMessage.Trim();
            }
        }

    And in abcd.svc.cs

    public class abcd : iabcd { //blah } public PostPhoneCallResponse PostPhoneCall(PostPhoneCallRequest objCDRRequest) { // }

    // many method.

    Then how to write code to retrieve it from the service?

    Thanks.



    • Edited by ardmore Monday, February 18, 2013 9:45 PM edit
    • Moved by Bob Shen Tuesday, February 19, 2013 6:24 AM
    Monday, February 18, 2013 8:07 PM

Answers

  • Hi,

    If the service are created and run properly( you can check by view the .svc file in browser) and you want to consume the service from a client app, you can "Add Service Reference", then call the service like:

    using (ServiceReference1.Service1Client proxy = new ServiceReference1.Service1Client())
                {
    //call the method of the service with proxy.yourmethod
                    Console.WriteLine(proxy.GetData(4).ToString());
                };

    In addtion, you may take a look at a basic example in below blog to get how to create and consume a WCF service.

    #Creating and Consuming Your First WCF Service

    http://www.codeproject.com/Articles/42643/Creating-and-Consuming-Your-First-WCF-Service

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by ardmore Wednesday, February 20, 2013 1:15 PM
    Wednesday, February 20, 2013 2:38 AM
    Moderator

All replies


  • There is a MSDN WCF forum,  and someone there will discuss with you the the WCF request and respond design pattern.

    Monday, February 18, 2013 10:52 PM
  • I don't have an endpoint, I only have service's http address. How to consume it?
    Tuesday, February 19, 2013 3:32 PM
  • Hi,

    If the service are created and run properly( you can check by view the .svc file in browser) and you want to consume the service from a client app, you can "Add Service Reference", then call the service like:

    using (ServiceReference1.Service1Client proxy = new ServiceReference1.Service1Client())
                {
    //call the method of the service with proxy.yourmethod
                    Console.WriteLine(proxy.GetData(4).ToString());
                };

    In addtion, you may take a look at a basic example in below blog to get how to create and consume a WCF service.

    #Creating and Consuming Your First WCF Service

    http://www.codeproject.com/Articles/42643/Creating-and-Consuming-Your-First-WCF-Service

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by ardmore Wednesday, February 20, 2013 1:15 PM
    Wednesday, February 20, 2013 2:38 AM
    Moderator
  • One following question, when you say

    using (ServiceReference1.Service1Client proxy = new ServiceReference1.Service1Client())

    What is

    Service1Client 

    Does intelisense create it?

    Thursday, February 21, 2013 1:38 AM
  • Hi,

    It is the proxy class that automatically generated by adding a service reference, you can use this class to create a proxy instance.

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, February 21, 2013 1:58 AM
    Moderator